Auto change the font size to fit the button in swift

后端 未结 4 1678
青春惊慌失措
青春惊慌失措 2021-02-20 07:47

I have tried this but it didn\'t work, the text is out of the button boundaries.

button.titleLabel!.adjustsFontSizeToFitWidth = true
button.titleLabel!.numberOfL         


        
4条回答
  •  逝去的感伤
    2021-02-20 08:12

    This worked for me:

     button.titleLabel?.font = UIFont(name: "Avenir Next", size: 20)
        button.titleLabel?.adjustsFontSizeToFitWidth = true
        button.titleLabel?.numberOfLines = 1
        button.titleLabel?.minimumScaleFactor = 0.1
        button.clipsToBounds = true
    

提交回复
热议问题