In iOS 6 i was using this method:
[self.handText sizeWithFont:font
minFontSize:10.0f
actualFontSize:&maxFontSize
forWidth:handWidth/2
lineBreakMode:UILineBreakModeClip];
xcode 5 says that 'sizeWithFont:minFontSIze:actualFontSize:forWidth:lineBreakMode:' is deprecated:first deprecated in iOS 7
Now i implemented like this:
[self.handText sizeWithAttributes:@{NSFontAttributeName:font}
minFontSize:10.0f
actualFontSize:&maxFontSize
forWidth:handWidth/2
lineBreakMode:NSLineBreakByClipping];
here xcode throws another warning saying:
'Instance method -sizeWithAttributed:minFontSize:forWidth:lineBreakMode:'not found(return type defaults to 'id')
Can anyone please help me to fix this warning.
Use this helper method instead:
-(CGSize)frameForText:(NSString*)text sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode {
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = lineBreakMode;
NSDictionary * attributes = @{NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraphStyle
};
CGRect textRect = [text boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];
//Contains both width & height ... Needed: The height
return textRect.size;
}
Use like so, if you need to support both iOS 6 and iOS 7:
#ifdef __IPHONE_7_0
titleSize = [self frameForText:self.titleLabel.text sizeWithFont:self.titleLabel.font constrainedToSize:CGSizeMake(labelMaxWidth,self.titleLabel.font.lineHeight) lineBreakMode:self.titleLabel.lineBreakMode ];
subtitleSize = [self frameForText:self.subtitleLabel.text sizeWithFont:self.subtitleLabel.font constrainedToSize:CGSizeMake(labelMaxWidth,self.subtitleLabel.font.lineHeight) lineBreakMode:self.subtitleLabel.lineBreakMode];
#else
titleSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font
constrainedToSize:CGSizeMake(labelMaxWidth,self.titleLabel.font.lineHeight)
lineBreakMode:self.titleLabel.lineBreakMode];
subtitleSize = [self.subtitleLabel.text sizeWithFont:self.subtitleLabel.font
constrainedToSize:CGSizeMake(labelMaxWidth,self.subtitleLabel.font.lineHeight)
lineBreakMode:self.subtitleLabel.lineBreakMode];
#endif
The method signature is:
- (CGSize)sizeWithAttributes:(NSDictionary *)attrs
which means you cannot specify any more argument than the first one (array of attributes). So, you are basically using a method (sizeWithAttributed:minFontSize:forWidth:lineBreakMode:
) which is not existing in the iOS SDK.
For a workaround, please have a look at this question.
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