user3094994
user3094994

Reputation: 99

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

[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

Upvotes: 6

Views: 2193

Answers (1)

i.AsifNoor
i.AsifNoor

Reputation: 587

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.

Upvotes: 7

Related Questions