iOS 6.0 までの下位互換性を持つ iOS アプリケーションを作成しています。
iOS 7 では、NSString
インスタンス メソッドdrawInRect:withAttributes:
が に置き換えられましdrawInRect:withFont:lineBreakMode:alignment:
た。使用する方法を決定するために、次のコードがあります。
if ([NSString instancesRespondToSelector:@selector(drawInRect:withAttributes:)]) {
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
[textStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[textStyle setAlignment:NSTextAlignmentLeft];
[[self title] drawInRect:_textRect withAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:FONT_SIZE], NSParagraphStyleAttributeName: textStyle}];
}
else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[[self title] drawInRect:_textRect withFont:[UIFont boldSystemFontOfSize:FONT_SIZE] lineBreakMode:NSLineBreakByTruncatingTail alignment:NSTextAlignmentLeft];
#pragma clang diagnostic pop
}
drawInRect:withAttributes:
は iOS 7 で導入されたためinstancesRespondToSelector:
、以前のバージョンの iOS で実行している場合は false を返す必要があります。ただし、iOS 6.1 を実行しているデバイスでこれをテストすると、true が返され、その後 を呼び出そうとするとクラッシュしますdrawInRect:withAttributes:
。何が起こっているのか、または私が間違っていることを知っている人はいますか?