drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:警告 [英] drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning

查看:258
本文介绍了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.

这篇关于drawInRect:withFont:lineBreakMode:alignment:'不推荐使用:警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆