我正在开发应用程序的新版本,并尝试替换已弃用的消息,但无法克服这一问题。
我不明白为什么drawInRect:withAttributes
不管用。代码正确显示时drawInRect:withFont:lineBreakMode:alignment
消息已发送,但在以下情况下不起作用drawInRect:withAttributes
已发送。
我使用相同的矩形和字体,并且我相信是相同的文本样式。常量只是将矩形定位在图像下方,但我在两次调用中使用相同的矩形,所以我确信矩形是正确的。
(注意bs.name下面使用的是 NSString 对象)
CGRect textRect = CGRectMake(fCol*kRVCiPadAlbumColumnWidth,
kRVCiPadAlbumColumnWidth-kRVCiPadTextLabelYOffset,
kRVCiPadAlbumColumnWidth,
kRVCiPadTextLabelHeight);
NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
textStyle.lineBreakMode = NSLineBreakByWordWrapping;
textStyle.alignment = NSTextAlignmentCenter;
UIFont *textFont = [UIFont systemFontOfSize:16];
使用上面的变量这是行不通的(屏幕上没有绘制任何内容)
[bs.name drawInRect:textRect
withAttributes:@{NSFontAttributeName:textFont,
NSParagraphStyleAttributeName:textStyle}];
使用上面的相同变量确实有效(字符串在屏幕上正确绘制)
[bs.name drawInRect:textRect
withFont:textFont
lineBreakMode:NSLineBreakByWordWrapping
alignment:NSTextAlignmentCenter];
任何帮助都会很棒。谢谢。