How to render stretched text in iOS?

前端 未结 3 835
醉梦人生
醉梦人生 2020-12-23 23:51

Given a rectangular area, I want to render some text using a specific font and have the rendered text fill out the rectangle. As in the image below:

相关标签:
3条回答
  • 2020-12-24 00:14

    you can also try with the UILabel's @property(nonatomic) BOOL adjustsFontSizeToFitWidth and @property minimumFontSize

    Initially you can set the much higher value for font property and also initialize the minimumFontSize with a minimum font value.

    0 讨论(0)
  • 2020-12-24 00:25

    You can set the UILabel transform property and scale the width:

    [myLabel sizeToFit];
    myLabel.transform = CGAffineTransformMakeScale(0.5, 1.0);
    
    0 讨论(0)
  • 2020-12-24 00:37

    You could try CoreText. Get a CTFramesetter, calculate its rect, then calculate the affine transform necessary to compress that rect into the bounds you want and set that as the CTM. Then when you draw the text, it should stretch it appropriately at full quality.

    0 讨论(0)
提交回复
热议问题