0
我正在尝试在程序中在使用Open Source software
创建的循环加载图像中添加一个label
。我面临的问题是我不知道如何标签,使其包含在圆圈内。我试图将CAShapeLayer
与UILabel
进行比较,但这不会起作用,因为CAShapeLayer
不是可从Storyboard
获得的类型。有没有我应该遵循的建议修复?以编程方式为UILabel添加一个圆形加载动画的约束
let circlePathLayer = CAShapeLayer()
var circleRadius: CGFloat = 100.0
var circleCenter: CGPoint = CGPoint()
func displayStatus() {
let statusLabel = UILabel(frame: CGRectMake(0, 0, 200, 21))
statusLabel.center = CGPointMake(160, 284)
statusLabel.textAlignment = NSTextAlignment.Center
statusLabel.textColor = UIColor.whiteColor()
statusLabel.text = "(Up)loading"
let horizontalConstraint = NSLayoutConstraint(item: statusLabel, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: circlePathLayer, attribute: NSLayoutAttribute.CenterX, multiplier: 1, constant: 0) //ERROR
self.addConstraint(horizontalConstraint)
let verticalConstraint = NSLayoutConstraint(item: statusLabel, attribute: NSLayoutAttribute.CenterY, relatedBy: NSLayoutRelation.Equal, toItem: circlePathLayer, attribute: NSLayoutAttribute.CenterY, multiplier: 1, constant: 0) //ERROR
self.addConstraint(verticalConstraint)
self.addSubview(statusLabel)
}
做哟你有这个Swift版本吗? –
用Swift Code更新。 –