How to adjust and make the width of a UILabel to fit the text size?

后端 未结 8 2227
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 06:01

In my project, there is a UILabel with text. The font size is 16pt. The text contents are changed depending on different cases. I hope it can automatically adju

8条回答
  •  無奈伤痛
    2020-12-13 06:41

    Follow this.

    CGSize stringsize = [yourString sizeWithFont:[UIFont systemFontOfSize:fontSize]]; 
    [label setFrame:CGRectMake(x,y,stringsize.width,height)];
    [label setText: yourString];
    

提交回复
热议问题