[string drawInRect: rect
withFont: self.font
lineBreakMode: NSLineBreakByWordWrapping
alignment: NSTextAlignmentCenter];
[((NSString *)[dayTitles objectAtIndex:index]) drawInRect: dayHeaderFrame
withFont: calendarFont
lineBreakMode: NSLineBreakByWordWrapping
alignment: NSTextAlignmentCenter];
在此代码中,我在iOS 7中收到以下警告:
/wm/Traffic_Department/PMCalendar/src/PMCalendarView.m:150:56:'drawInRect:withFont:lineBreakMode:alignment:'已弃用:首先在iOS 7.0中弃用 - 使用-drawInRect:withAttributes:
如何删除此警告?
由于
答案 0 :(得分:7)
试试以下内容。
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是您要绘制的字符串。 我希望它有所帮助。