Scaling font size to fit vertically in UILabel

前端 未结 2 1803
野的像风
野的像风 2021-02-02 13:00

I want to take a standard UILabel and increase the font size so that it fills the vertical space. Taking inspiration from the accepted answer for this question, I defined a sub

2条回答
  •  失恋的感觉
    2021-02-02 13:24

    Your calculation for pointsPerPixel is the wrong way up, it should be...

    float pointsPerPixel =  self.font.pointSize / size.height;
    

    Also, maybe this code should be in layoutSubviews as the only time the font should be changed is when the frame size changes.

提交回复
热议问题