Can I set the UILabel to expand according to an arbitrary amount of text?
This question is more suitable for development purposes and will never be used for a delivery app. I need to make a quick and dirty UILabel whose textbox I can point to a really, really, long string. Really long. I am but futzing at IB and cannot figure out the correct magic handshake to allow UILabel to run for a really big size. Does anyone have any idea?
Cheers, Doug
+2
source to share
1 answer
You can use the method in the UIKit extensions to NSString to achieve this goal . You can get the size using this method :
- (CGSize)sizeWithFont:(UIFont *)font
minFontSize:(CGFloat)minFontSize
actualFontSize:(CGFloat *)actualFontSize
forWidth:(CGFloat)width
lineBreakMode:(UILineBreakMode)lineBreakMode
Set the size of the label to the return value of this method and everything will be set.
EDIT: This method is for single line strings. If your line is more than one line then use this method :
- (CGSize)sizeWithFont:(UIFont *)font
constrainedToSize:(CGSize)size
lineBreakMode:(UILineBreakMode)lineBreakMode
+11
source to share