drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:警告
问题描述:
[string drawInRect: rect
withFont: self.font
lineBreakMode: NSLineBreakByWordWrapping
alignment: NSTextAlignmentCenter];
[((NSString *)[dayTitles objectAtIndex:index]) drawInRect: dayHeaderFrame
withFont: calendarFont
lineBreakMode: NSLineBreakByWordWrapping
alignment: NSTextAlignmentCenter];
在此代码中,我在iOS 7中收到以下警告:
In this code I am getting the below warning in iOS 7:
/wm/Traffic_Department/PMCalendar/src/PMCalendarView.m:150:56:'drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:首先在iOS 7.0中弃用 - 使用-drawInRect:withAttributes:
/wm/Traffic_Department/PMCalendar/src/PMCalendarView.m:150:56: 'drawInRect:withFont:lineBreakMode:alignment:' is deprecated: first deprecated in iOS 7.0 - Use -drawInRect:withAttributes:
如何删除此警告?
谢谢
答
请尝试以下操作。
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是您想要绘制的字符串。
我希望它有所帮助。
While textToDraw is string that you want to draw. I hope it helps.