Can anyone please help me to fix this warning?
'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:
-(CGFloat)setLableSizeAccordingToText:(NSString*)text andSetX:(CGFloat)x Y:(CGFloat)y{
self.text = text;
CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);
CGSize expectedLabelSize = [text sizeWithFont:self.font constrainedToSize:maximumLabelSize lineBreakMode:self.lineBreakMode];
CGRect frame = CGRectMake(x, y, expectedLabelSize.width+lblHorizontalPadding , lblHeight);
self.frame = frame;
return expectedLabelSize.width + lblHorizontalPadding;
}
The new sizeWithAttributes
combined with NSParagraphStyle
should do the job for you.
NSMutableDictionary *attributes = [NSMutableDictionary new];
[attributes setObject:self.font forKey:NSFontAttributeName];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = self.lineBreakMode;
//paragraphStyle.alignment = self.textAlignment; //uncomment this if you need specific text alignment
[attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
CGSize expectedLabelSize = [text sizeWithAttributes:attributes];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments