如何根据字体大小更改 UILabel 大小?
How do I change UILabel size depending on its font size?
@IBAction func sizeChanged(sender: UISlider) {
let senderValue = CGFloat(sender.value)
myLabel?.font = UIFont(name: (myLabel?.font.fontName)!, size:senderValue * 20)}
我想用滑块更改 myLabel.font
大小,但是 myLabel
不会随着字体大小的增加而调整其宽度和高度。
如何更改 UILabel
大小以适应其字体大小?
谢谢。
更新 UILabel
的字体大小后,您需要调用 sizeToFit()
。
myLabel?.sizeToFit()
Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.
myLabel?.sizeToFit() 将设置标签的大小以适合其内容...只需确保您没有为标签添加高度和宽度限制。
@IBAction func sizeChanged(sender: UISlider) {
let senderValue = CGFloat(sender.value)
myLabel?.font = UIFont(name: (myLabel?.font.fontName)!, size:senderValue * 20)}
我想用滑块更改 myLabel.font
大小,但是 myLabel
不会随着字体大小的增加而调整其宽度和高度。
如何更改 UILabel
大小以适应其字体大小?
谢谢。
更新 UILabel
的字体大小后,您需要调用 sizeToFit()
。
myLabel?.sizeToFit()
Call this method when you want to resize the current view so that it uses the most appropriate amount of space. Specific UIKit views resize themselves according to their own internal needs. In some cases, if a view does not have a superview, it may size itself to the screen bounds. Thus, if you want a given view to size itself to its parent view, you should add it to the parent view before calling this method.
myLabel?.sizeToFit() 将设置标签的大小以适合其内容...只需确保您没有为标签添加高度和宽度限制。