【发布时间】:2018-02-14 11:44:38
【问题描述】:
我知道我可以通过使用自动收缩来动态改变 UIlabel 的字体大小。但是 UIbuttons 没有自动收缩属性,
那么如何根据按钮的大小动态更改按钮的字体大小?
代码:
导入 UIKit
类视图控制器:UITableViewController {
@IBAction func myButt(_ sender: UIButton) {}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myButt.titleLabel?.adjustsFontSizeToFitWidth = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
return cell
}
}
【问题讨论】:
标签: ios swift xcode uibutton storyboard