草庐IT

codedLabel

全部标签

ios - Swift 3 以编程方式创建 UILabel 并添加 NSLayoutConstraints

你好我正在尝试以编程方式创建一个标签并添加NSLayoutConstraints以便它在superView中居中,而不管屏幕大小和方向等。我已经看过但找不到可遵循的示例。这是我所拥有的:letcodedLabel:UILabel=UILabel()codedLabel.frame=CGRect(x:100,y:100,width:200,height:200)codedLabel.textAlignment=.centercodedLabel.text=alertTextcodedLabel.numberOfLines=1codedLabel.textColor=UIColor.red

ios - Swift 3 以编程方式创建 UILabel 并添加 NSLayoutConstraints

你好我正在尝试以编程方式创建一个标签并添加NSLayoutConstraints以便它在superView中居中,而不管屏幕大小和方向等。我已经看过但找不到可遵循的示例。这是我所拥有的:letcodedLabel:UILabel=UILabel()codedLabel.frame=CGRect(x:100,y:100,width:200,height:200)codedLabel.textAlignment=.centercodedLabel.text=alertTextcodedLabel.numberOfLines=1codedLabel.textColor=UIColor.red