我希望为这些UILabels添加额外的填充。我使用以下代码更改了内在内容大小:
class CustomLabelWithPadding:UILabel{
override func intrinsicContentSize() -> CGSize {
let contentSize = super.intrinsicContentSize()
return CGSize(width: contentSize.width + 50, height: contentSize.height)
}
}
let label = CustomLabelWithPadding()
label.text = "Hello World"
label.font = UIFont(name: "Helvetica", size: 20)
label.sizeToFit()
label.layer.backgroundColor = UIColor(red: 0.067, green: 0.773, blue: 0.525, alpha: 1.00).CGColor
label.textAlignment = NSTextAlignment.Center
label.textColor = UIColor.whiteColor()
label.frame.origin.x = 160
label.frame.origin.y = 50
self.view.addSubview(label)
答案 0 :(得分:0)
这个人完成了这项工作:)
{{1}}