How can I adjust the label Width according to the text? If text length is small I want the label width small...If text length is small I want the label width according to th
sizeWithFont constrainedToSize:lineBreakMode:
is the original method to use. Here is an example of how to use it is below:
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;