我正在尝试更新我的应用程序以在 IOS 7 上运行并收到错误消息,告诉我以下代码已弃用并与属性一起使用。苹果开发者网站只是说它已被弃用,但没有给出如何修复它的线索。任何人都可以将我的代码翻译成任何新格式吗?
[str drawInRect: r
withFont: f1
lineBreakMode: NSLineBreakByWordWrapping
alignment: NSTextAlignmentCenter];
使用以下内容:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentCenter;
[str drawInRect:rect withAttributes: @{NSFontAttributeName: f1,
NSParagraphStyleAttributeName: paragraphStyle }];
尝试跟随。
NSString *font = @"Courier-Bold";
#ifdef __IPHONE_7_0
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
paragraphStyle.alignment = NSTextAlignmentCenter;
[textToDraw drawInRect:renderingRect withAttributes: @{NSFontAttributeName: font,
NSParagraphStyleAttributeName: paragraphStyle }];
#else
[textToDraw drawInRect:renderingRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter];
#endif
而 textToDraw 是您要绘制的字符串。我希望它有所帮助。