此方法在 iOS 7.0 中已弃用:
drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment:
现在drawInRect:withAttributes:
改用。
我找不到fontSize 和baselineAdjustment 的attributeName。
编辑
感谢@Puneet 的回答。
实际上,我的意思是如果没有这些密钥,如何在 iOS 7 中实现此方法?
像下面的方法:
+ (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;
}
我不知道如何通过fontSize
和baselineAdjustment
到
attributes
字典。
例如
NSBaselineOffsetAttributeName
key 应该传递NSNumer
给它,但是baselineAdjustment
is Enum
。
难道没有其他方法可以传递这两个变量吗?