gpt4 book ai didi

ios - 从 UILabel 到 UIImage 画一条线

转载 作者:可可西里 更新时间:2023-11-01 00:50:59 25 4
gpt4 key购买 nike

我试图以编程方式从标签的底部中心到图像的顶部中心画一条线,但经过大量谷歌搜索后我无法弄清楚如何。我有一个 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)
}

}

Picture of what I am trying to achieve enter image description here任何帮助都会很棒,因为我对这一切还很陌生,而谷歌并没有为我提供太多帮助。

提前感谢您的帮助。

最佳答案

试试这个……!

-(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];
}

关于ios - 从 UILabel 到 UIImage 画一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39165593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com