This method is deprecated in iOS 7.0:
drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:
Now use drawInRect:withAttributes:
instead.
I can't find the attributeName of fontSize and baselineAdjustment.
Edit
Thanks @Puneet answer.
Actually, I mean if there doesn't have these key, how to implement this method in iOS 7?
Like below method:
+ (CGSize)drawWithString:(NSString *)string atPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font fontSize:(CGFloat)fontSize
lineBreakMode:(IBLLineBreakMode)lineBreakMode
baselineAdjustment:(UIBaselineAdjustment)baselineAdjustment {
if (iOS7) {
CGRect rect = CGRectMake(point.x, point.y, width, CGFLOAT_MAX);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = lineBreakMode;
NSDictionary *attributes = @{NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle};
[string drawInRect:rect withAttributes:attributes];
size = CGSizeZero;
}
else {
size = [string drawAtPoint:point forWidth:width withFont:font fontSize:fontSize lineBreakMode:lineBreakMode baselineAdjustment:baselineAdjustment];
}
return size;
}
I don't know how to pass fontSize
and baselineAdjustment
to
attributes
dictionary.
e.g.
NSBaselineOffsetAttributeName
key should pass a NSNumer
to it, but the baselineAdjustment
is Enum
.
Isn't there have other way to pass the two variables?
question from:
https://stackoverflow.com/questions/19442653/how-to-use-drawinrectwithattributes-instead-of-drawatpointforwidthwithfontf 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…