我已经从故事板创建了一个标签,现在我正在尝试为该标签提供填充。我创建了一个类并尝试了以下两种方法,但没有任何效果。请帮忙。
override func drawTextInRect(rect: CGRect) {
super.drawTextInRect(UIEdgeInsetsInsetRect(rect, UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)))
}
let padding = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
override func intrinsicContentSize() -> CGSize {
let superContentSize = super.intrinsicContentSize()
let width = superContentSize.width + padding.left + padding.right
let heigth = superContentSize.height + padding.top + padding.bottom
return CGSize(width: width, height: heigth)
}
Run Code Online (Sandbox Code Playgroud) 我有一个UILabel,其字体大小将增加捏手势iOS swift.我能够增加字体大小,但视图有问题.思想sizeToFit()根据需要增加高度和宽度,但它不会反映在视图上,即标签在视图中保持不变.随着字体大小的增加,请帮我增加标签的大小.
@IBAction func increaseTextFont(sender: UIPinchGestureRecognizer) {
var pinchScale = sender.scale
pinchScale = round(pinchScale * 1000) / 1000.0
if (pinchScale < 1) {
testLabel.font = UIFont( name: "arial", size: testLabel.font.pointSize - pinchScale)
}
else{
testLabel.font = UIFont( name: "arial", size: testLabel.font.pointSize + pinchScale)
}
testLabel.frame.height * pinchScale))
testLabel.frame.size.height *= pinchScale
testLabel.frame.size.width *= pinchScale
self.testLabel.layoutIfNeeded()
print(testLabel.frame.size.height)
print(testLabel.frame.size.width)
}
Run Code Online (Sandbox Code Playgroud)