我有一个UILabel
我想在顶部和底部添加空间。使用约束中的最小高度,我将其修改为:
编辑:要做到这一点,我使用了:
override func drawTextInRect(rect: CGRect) {
var insets: UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 10.0, bottom: 0.0, right: 10.0)
super.drawTextInRect(UIEdgeInsetsInsetRect(rect, insets))
}
但我必须找到一种不同的方法,因为如果我编写两行以上的代码,问题是相同的:
发布于 2017-03-08 06:17:42
只需使用自动布局:
let paddedWidth = myLabel.intrinsicContentSize.width + 2 * padding
myLabel.widthAnchor.constraint(equalToConstant: paddedWidth).isActive = true
好了。
https://stackoverflow.com/questions/27459746
复制相似问题