How to adjust font size of label to fit the rectangle?

前端 未结 14 768
独厮守ぢ
独厮守ぢ 2020-11-28 07:00

Yeah, there\'s this cool myLabel.adjustsFontSizeToFitWidth = YES; property. But as soon as the label has two lines or more, it won\'t resize the text to anythin

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 07:12

    Since I didn't find a working solution answering to all my needs using the above answers, I have created my own components providing the following features: FittableFontLabel

    • Adjust font to fit height and width when using multilines label
    • Adjust font to fit width when using single line label, the height label will resize itself
    • Support for NSAttributedStrings as well as basic string
    • Auto adjusting the size when changing a label text / frame
    • ...

    If any of you is interesting, it's a full swift library available using CocoaPods: https://github.com/tbaranes/FittableFontLabel

提交回复
热议问题