我正在开发我的应用的新版本,试图替换已弃用的消息,但是无法通过此问题。
我不明白为什么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];
希望能得到任何帮助,谢谢。
drawInRect:withAttributes:
不起作用是什么意思? - Arek HolkodrawInRect:withFont:lineBreakMode:alignment
方法时,包含在bs.name
中的字符串会被正确地绘制到屏幕上,但是在使用drawInRect:withAttributes
方法时(什么都没有被绘制)。 - Ross Pirtle