Monday, 21 July 2014

Dynamic Height For UILabel

label.textAlignment= NSTextAlignmentCenter;
label.lineBreakMode= NSLineBreakByWordWrapping;
label.numberOfLines=0;
CGSize newSize = [label.text boundingRectWithSize:CGSizeMake(label.frame.size.width, MAXFLOAT)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:label.font}context:nil].size;
CGRect labelFrame=label.frame;
labelFrame.size.height=newSize.height;
label.frame=labelFrame;

No comments:

Post a Comment