sizeToFit label voids align right / set minimum width of label
Posted
by
Deco
on Stack Overflow
See other posts from Stack Overflow
or by Deco
Published on 2011-11-23T01:45:51Z
Indexed on
2011/11/23
1:51 UTC
Read the original article
Hit count: 265
Here is my code I am using to make a label (which contains content of an unknown length) the correct height for the content. (lines is equal to 0)
myLabel.text =[NSString stringWithFormat:@"%@", myLabelContent];
myLabel.frame = CGRectMake(myLabel.frame.origin.x, myLabel.frame.origin.y, myLabel.frame.size.width, 800);
[myLabel sizeToFit];
The only problem is, it is resizing the width as well as the height. I have two labels side by side, one aligned left, one aligned right. The left aligned one works fine.
However, the right aligned one becomes intended (from the right). Because of its width resize, the content always starts at the origin.x position (in effect) because the label is made to be the shortest width required. I hope that makes sense.
Is there a way to override or reset the width after auto resize had solved the height problem, or set a minimum width for the label?
Many Thanks in advance, Deco
© Stack Overflow or respective owner