Reputation: 711
I want to show the Text Like as below.
My content of Label may be changed & according to that my Label Frame should be Adjust Automatically.
How can I do this?
My Try
//NSString* string = @"Previously scheduled for every Monday, Happy will now be moving to Wednesdays at the same time. The time from 5:00 pm - 7:00 pm will remain the same. Now starting April 14th until further notice.";
NSString* string=@"ABCDEF";
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.minimumLineHeight = 30.f;
style.maximumLineHeight = 30.f;
style.firstLineHeadIndent=100.0f;
NSDictionary *attributtes = @{NSParagraphStyleAttributeName : style,};
lbl_notification.attributedText = [[NSAttributedString alloc] initWithString:string attributes:attributtes];
Upvotes: 2
Views: 1008
Reputation: 8444
If you want the label frame to be changed according to the text, the below code will be helpful,
CGSize Size1 = yourlabel.bounds.size;
CGSize Size2 = CGRectInfinite.size;
Size2.width = Size1.width;
Size2 = [yourlabel.text sizeWithFont:yourlabel.font constrainedToSize:Size2];
yourlabel.frame = CGRectMake(yourlabel.frame.origin.x, yourlabel.frame.origin.y, Size2.width, Size2.height);
Upvotes: 1
Reputation: 3928
Set your label text
Yourlabel.text=[NSString stringWithFormat:@"Notification: %@",Dynamic text];
Yourlabel.adjustsFontSizeToFitWidth = YES;
Upvotes: 2
Reputation: 25459
This works for me:
_label = [[UILabel alloc] init];
_label.lineBreakMode = NSLineBreakByWordWrapping;
_label.numberOfLines = 0;
_label.text = .....
[_label setFrame:CGRectMake(0.0f, 0.0f, 340.0f, 300.0f)];
_labelSize = [_label.text sizeWithFont:_label.font constrainedToSize:_label.frame.size lineBreakMode:NSLineBreakByWordWrapping];
[_label setFrame:CGRectMake(0.0f, 0.0f, 340.0f, _labelSize.height)];
Upvotes: 1
Reputation: 451
Try this, it will shrink the size of font if text it is too much , in order to fit that in labe:
displayLabel.adjustsFontSizeToFitWidth = YES;
Upvotes: 1