I have a custom uitableviewcell with several labels and I would like for some of them to autoresize their frame (width) based on the content (text). I am not sure how to accomplish that. I tried to set fixed frame of the label and after apply autoresizingMask, but that doesn't do the trick. Any *pointer to a sample?
A:
If you just want to make so that the label fits in multiple lines, you have to say:
cell.textLabel.numberOfLines = 0;
However I'm not sure if this is the one that you want... Usually if the content is text than that'll be what you want.
the_great_monkey
2010-06-21 13:22:27
A:
If you want to adjust the frame of a label to fit the labels text, just call
[label sizeToFit];
This will fit in both dimensions.
tonklon
2010-07-02 17:12:44
+1
A:
Use This method:
CGSize *size = [label.text sizeWithFont:fontOfLabelText];
float widthOfLabel = size.width;
size.width will return the actual width that the text in the label will occupy on the screen. Set the label width equal to width of text.
Ideveloper
2010-07-03 06:17:21
Exactly what I was looking for, thanks.
Peter Pajchl
2010-07-03 10:50:29