The first thing you need to do is get the size of the text.
Fortunately, the NCCtring UIKit link complements the link and offers a method for doing just that:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
This will give you CGSize , which you can then use to set the frame of your UILabel or any other UIView subclass that you use.
So, if textLayer is a UILabel - and not a CALayer , you will get something like this:
UIFont *myFont = [UIFont boldSystemFontOfSize:12.0f]; CGSize myFontSize = [myString sizeWithFont:myFont]; myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, myFontSize.width, myFontSize.height)]; myLabel.text = newTitle; myLabel.font = myFont;
source share