【发布时间】:2019-01-24 00:34:57
【问题描述】:
我有一个大小为 50x50 的 UIButton。如何将 titleLable 的字体大小设置为小于 adjustFontSizeToFitWidth 创建的大小,以便字体大小适合让我们说像 30x30 这样的自定义框架,而 UIButton 的大小是 50x50?
let but:UIButton = UIButton(frame: CGRect(x: 80, y: 80, width: 70, height: 50))
view.addSubview(but)
but.backgroundColor = .white
but.titleLabel?.backgroundColor = .green
but.setTitle("hello", for: .normal)
but.setTitleColor(.red, for: .normal)
//this gives the second image, still having the text uncentered.
//but.contentVerticalAlignment = .fill
but.titleLabel?.font = UIFont(name: "WarsawGothicSuExt", size: 60)
but.contentEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
but.titleLabel?.adjustsFontSizeToFitWidth = true
but.layoutIfNeeded()
【问题讨论】: