从UILabel到UIImage画一条线

瓦扎

我正在尝试以编程方式从标签的底部中心到图像的顶部中心画一条线,但是经过大量的搜索之后,我不知道怎么做。我有一个for循环,用于创建它们指向的图像和标签,因此需要将其写入以适合此循环,以便它创建与其标签/图像关联的所有行,并相应地定位它们。

这是循环:

    for i in 0..<hotspots.count {

        let hotspotImageButton = UIButton(type: .Custom)
        let hotspotTitleLabel = UILabel(frame: CGRect.zero)
        let hotspotTextLabel = UILabel(frame: CGRect.zero)

        hotspotImageButton.translatesAutoresizingMaskIntoConstraints = false
        hotspotTitleLabel.translatesAutoresizingMaskIntoConstraints = false
        hotspotTextLabel.translatesAutoresizingMaskIntoConstraints = false

        let whiteHotspotImage = UIImage(named: hotspots[i].image)?.imageWithRenderingMode(.AlwaysTemplate)

        hotspotImageButton.setImage(whiteHotspotImage, forState: .Normal)
        hotspotImageButton.imageView?.tintColor = UIColor.redColor()
        hotspotTitleLabel.text = hotspots[i].title
        hotspotTextLabel.text = hotspots[i].text

        hotspotTitleLabel.textColor = UIColor.whiteColor()
        hotspotTitleLabel.font = UIFont(name: "Helvetica", size: 13)
        hotspotTextLabel.textColor = UIColor.whiteColor()
        hotspotTextLabel.font = UIFont(name: "Helvetica", size: 12)


        standMapImage.addSubview(hotspotImageButton)
        standMapImage.addSubview(hotspotTitleLabel)
        standMapImage.addSubview(hotspotTextLabel)

        hotspotImageButton.snp_makeConstraints { make in
            make.leading.equalTo(standMapImage.snp_leadingMargin).multipliedBy(hotspots[i].hotspotXCoordinate)
            make.top.equalTo(standMapImage.snp_topMargin).multipliedBy(hotspots[i].hotspotYCoordinate)
            make.width.equalTo(standMapImage.snp_width).multipliedBy(0.1)
            make.height.equalTo(hotspotImageButton.snp_width)
        }

        hotspotTitleLabel.snp_makeConstraints { make in
            make.leading.equalTo(standMapImage.snp_leadingMargin).multipliedBy(hotspots[i].titleXCoordinate)
            make.top.equalTo(standMapImage.snp_topMargin).multipliedBy(hotspots[i].titleYCoordinate)
        }

        hotspotTextLabel.snp_makeConstraints { make in
            make.centerX.equalTo(hotspotTitleLabel.snp_centerX)
            make.top.equalTo(hotspotTitleLabel.snp_bottom).inset(-4)
        }

    }

我要实现的目标的图片 在此处输入图片说明任何帮助都将非常有用,因为我对所有这些都相当新,而google并没有为我提供很多帮助。

感谢您的任何帮助。

斯里尼瓦斯

试试这个 ...!

-(void)createLineFrom:(UILabel *)base andTo:(UIImageView*)view{

    CGPoint basePoint = CGPointMake(base.bounds.origin.x+base.bounds.size.width/2,base.bounds.origin.y+base.bounds.size.height/2);
    CGPoint bellonPoint = CGPointMake((view.frame.origin.x+view.frame.size.width/2),view.frame.origin.y+view.frame.size.height);
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:basePoint];
    [path addLineToPoint:bellonPoint];

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [path CGPath];
    shapeLayer.strokeColor = [UIColor redColor].CGColor;
    shapeLayer.lineWidth = 2;
    shapeLayer.fillColor = [[UIColor redColor] CGColor];
    [self.layer addSublayer:shapeLayer];
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从UILabel到UIImage画一条线

来自分类Dev

BabylonJS画一条线

来自分类Dev

BabylonJS画一条线

来自分类Dev

慢慢画一条线

来自分类Dev

如何从一条点画一条线到多点列表

来自分类Dev

从起点(X,Y)到目的地(X,Y)画一条线

来自分类Dev

获取小部件的位置以允许从小部件a到b画一条线

来自分类Dev

高图:从标记到轴画一条线?

来自分类Dev

如何在CSS中从左右框到文本中间画一条线?

来自分类Dev

获取小部件的位置以允许从小部件a到b画一条线

来自分类Dev

用TLine从BottomLeft到TopRight画一条线

来自分类Dev

片段着色器-画一条线?

来自分类Dev

在Android中的ImageView上方画一条线

来自分类Dev

在UITextView内画一条线-NSAttributedString

来自分类Dev

如何用matplotlib画一条线?

来自分类Dev

在精灵套件中画一条线

来自分类Dev

如何画一条线WPF

来自分类Dev

在WinAPI中的单词旁边画一条线

来自分类Dev

用UIBezierPath画一条线

来自分类Dev

如何只画一条线

来自分类Dev

在画布上画一条线

来自分类Dev

用垂直装饰画一条线

来自分类Dev

迅速在NSView上画一条线

来自分类Dev

Java Swing,以特定角度画一条线?

来自分类Dev

为什么MoveTo()画一条线?

来自分类Dev

在jetpack中画一条线

来自分类Dev

在pyplot中的图例上画一条线

来自分类Dev

在现代OpenGL中画一条线

来自分类Dev

如何用pureimage画一条线?