I want to develop a functionality that to set frame of UILabel
according to its text means when text is change its frame is change? If yes, then please share any link or any idea to develop this.
Thanks in advance.
label.text = @"some text of random length";
[label sizeToFit];
If the text might be more than 1 line, add label.numberOfLines = 0;
before calling sizeToFit;
try this
NSString *sample = @"...";
CGSize txtSz = [sample sizeWithFont:[UIFont fontWithName: @"Helvetica" size: 16]];
CGRect lblFrame = CGRectMake(10,50, txtSz.width, txtSz.height);
yourLabel.frame = lblFrame;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With