How to make UILabel with autoresizingMask in a custom cell?

I have a custom uitableviewcell with several labels, and I would like some of them to automatically determine their frame (width) based on the content (text). I do not know how to do that. I tried to set a fixed label frame after applying autoresizingMask as well, but that doesn't do the trick. Any * sample pointer?

+3
source share
3 answers

Use the following method:

CGSize *size = [label.text sizeWithFont:fontOfLabelText];
float widthOfLabel = size.width;

size.width will return the actual width that the text on the label will occupy on the screen. Set the width of the label to the width of the text.

+2
source

,

[label sizeToFit];

.

+3

If you just want to make the label fit in multiple lines, you should say:

cell.textLabel.numberOfLines = 0;

However, I'm not sure if this is the one you want ... Usually, if the content is text, that will be what you want.

0
source

Source: https://habr.com/ru/post/1748744/


All Articles