我正在研究我的應用程序的新版本,並試圖替換棄用的消息,但無法通過這一個。drawInRect:withAttributes vs drawInRect:withFont:lineBreakMode:alignment
我想不通爲什麼drawInRect:withAttributes
不起作用。當發送drawInRect:withFont:lineBreakMode:alignment
消息時代碼正確顯示,但在發送drawInRect:withAttributes
時不起作用。
我使用相同的矩形和字體,我相信是相同的文字樣式。常量只是將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];
任何協助將是偉大的。謝謝。
你是說'drawInRect:withAttributes:'不起作用是什麼意思? –
非常好的問題。對不起,我沒有詳細說明。包含在bs.name中的字符串使用drawInRect在屏幕上正確繪製:withFont:lineBreakMode:alignment消息,但在使用drawInRect:withAttributes消息時不顯示(不繪製任何東西)。 –