I have a question about button title label size.
I want to enlarge the font size which button title label in iPad.
I try to use following code, but it seems not working to make label enlarge.
If I want to according the device to change font size, what should I do?
Take image for example.
Label size like following image.
This code is nice size working in iPhone, but it seems very small in iPad.
func CustomButton() -> UIButton {
let ui = UIButton()
ui.translatesAutoresizingMaskIntoConstraints = false
ui.contentMode = UIViewContentMode.scaleAspectFit
return ui
}
class FullWidthButton: UIView {
var button:UIButton = { () -> UIButton in
let ui:UIButton = CustomButton()
ui.titleLabel?.numberOfLines = 1
ui.titleLabel?.textAlignment = .center
ui.titleLabel!.minimumScaleFactor = 0.5
ui.titleLabel?.textColor = UIColor.white
ui.titleLabel?.font = UIFont.systemFont(ofSize: 16.0)
ui.titleLabel?.adjustsFontSizeToFitWidth = true
ui.titleLabel?.lineBreakMode = .byClipping
ui.backgroundColor = defaultButtonOrangeColor
ui.layer.cornerRadius = defaultButtonRadius
ui.layer.masksToBounds = true
return ui
}()
override init(frame: CGRect) {
super.init(frame:frame)
translatesAutoresizingMaskIntoConstraints = false
loadContent()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func layoutSubviews() {
super.layoutSubviews()
loadVFL()
}
func loadContent() {
addSubview(button)
}
func loadVFL() {
button.snp.makeConstraints { (make) in
make.width.height.leading.trailing.top.bottom.equalToSuperview()
}
}
}