我正在开发我的应用程序的一个新版本,并试图替换不受欢迎的消息,但无法通过这个版本。
我不明白为什么drawInRect:withAttributes
不工作。当发送drawInRect:withFont:lineBreakMode:alignment
消息时,代码将正确显示,但在发送drawInRect:withAttributes
时不起作用。
我用的是同样的字体和字体,我相信这是相同的文字风格。常量只是将rect定位在图像下面,但是对于两个调用,我使用的是相同的rect,所以我确信矩形是正确的。
(注意,下面使用的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];
任何帮助都是很好的。谢谢。
发布于 2013-10-10 10:18:10
要设置文本的颜色,需要将属性中的NSForegroundColorAttributeName
作为附加参数传递。
NSDictionary *dictionary = @{ NSFontAttributeName: self.font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: self.textColor};
https://stackoverflow.com/questions/19274408
复制相似问题