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

后端 未结 8 2226
被撕碎了的回忆
被撕碎了的回忆 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:19

    NSString *txt1=@"I am here.";
    CGSize stringsize1 = [txt1 sizeWithFont:[UIFont systemFontOfSize:14]]; 
    [label setFrame:CGRectMake(x,y,stringsize1.width,hieght)];
    [label setText:txt1];
    

提交回复
热议问题