Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drawInRect:withFont:lineBreakMode:alignment:' is deprecated: warning

Tags:

iphone

ios7

[string drawInRect: rect
              withFont: self.font
         lineBreakMode: NSLineBreakByWordWrapping
             alignment: NSTextAlignmentCenter];

[((NSString *)[dayTitles objectAtIndex:index]) drawInRect: dayHeaderFrame 
                                                     withFont: calendarFont 
                                                lineBreakMode: NSLineBreakByWordWrapping
                                                    alignment: NSTextAlignmentCenter];

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:' is deprecated: first deprecated in iOS 7.0 - Use -drawInRect:withAttributes:

How do I remove this warning?

Thanks

like image 562
user3094994 Avatar asked Dec 29 '13 06:12

user3094994


1 Answers

Try following.

 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

While textToDraw is string that you want to draw. I hope it helps.

like image 60
i.AsifNoor Avatar answered Sep 30 '22 17:09

i.AsifNoor