我似乎无法向我的UILabel
添加任何边距,并将其包装在堆栈视图中也无济于事。最好我可以告诉.layoutMargins
行完全被忽略了......
let helloLabel:UILabel = UILabel()
helloLabel.backgroundColor = UIColor.purpleColor()
helloLabel.text = "Hello, World!"
helloLabel.textAlignment = .Center
helloLabel.layoutMargins = UIEdgeInsetsMake(25,80,20,10)
stack.addArragnedSubView(helloLabel)
答案 0 :(得分:-1)
显然这是不可能做到的。但是,如果你可以接近顶部和底部边距相同的话,你可以接近......
let helloLabel:UILabel = UILabel()
helloLabel.backgroundColor = UIColor.purpleColor()
helloLabel.text = "Hello, World!"
helloLabel.textAlignment = .Center
stack.addArragnedSubView(helloLabel)
NSLayoutConstraint(item:stack, attribute:.Width, relatedBy:.Equal, toItem:self.view, attribute:.Width, multiplier:1, constant:0).active = true
//top margin
stack.spacing = 25
//left margin
NSLayoutConstraint(item:helloLabel, attribute:.Leading, relatedBy:.Equal, toItem:stack, attribute:.Leading, multiplier:1, constant:80).active = true
//right margin
NSLayoutConstraint(item:helloLabel, attribute:.Trailing, relatedBy:.Equal, toItem:stack, attribute:.Trailing, multiplier:1, constant:-10).active = true