Is it possible to vertically align text inside labels with a “large” frame

前端 未结 8 1564
梦谈多话
梦谈多话 2021-01-01 11:58

In my application I have multiple tableviews with custom cells. Some of the text in the cells are spread out on between 2-4 lines so the height of the label is large enough

8条回答
  •  伪装坚强ぢ
    2021-01-01 12:42

    Here is the Same Question asked by SomeOne. you'll find more appropriate way to solve this problem.they guys did great explanation over it.

    I think so, you should take a look of this.

    here in that thread many answers suggest set the dynamic frame for the UILabel on the basis of text as below snippet of code described.

        CGSize theStringSize = [textToBeUsed sizeWithFont:lblTitle.font  constrainedToSize:labelSize lineBreakMode:lblTitle.lineBreakMode];
        lblTitle.frame = CGRectMake(lblTitle.frame.origin.x, lblTitle.frame.origin.y, theStringSize.width, theStringSize.height);
        lblTitle.text = theText;
    
       // lblTitle is the Label used for showing the Text.
    

    you can get more precise idea rather than using textField here it is

提交回复
热议问题