drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:警告

时间:2013-12-29 06:58:03

标签: iphone ios7

[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:

如何删除此警告?

由于

1 个答案:

答案 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是您要绘制的字符串。 我希望它有所帮助。