Tag: drawinrect

drawInRect:withAttributes vs drawInRect:withFont:lineBreakMode:alignment

我正在研究我的应用程序的新版本,并试图replace弃用的消息,但无法超越这一个。 我不明白为什么drawInRect:withAttributes不起作用。 当drawInRect:withFont:lineBreakMode:alignment消息被发送时,代码正确显示,但在drawInRect:withAttributes发送时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]; 这不起作用(屏幕上没有画出)使用上面的variables [bs.name drawInRect:textRect withAttributes:@{NSFontAttributeName:textFont, NSParagraphStyleAttributeName:textStyle}]; 这样做的工作(string在屏幕上正确绘制)使用上面相同的variables [bs.name drawInRect:textRect withFont:textFont lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentCenter]; 任何援助将是伟大的。 谢谢。