2011-09-14 19 views

回答

2

drawInRect UIKit方法返回一個CGSize,它是繪製字符串的大小。將此與您傳遞給drawInRectCGRect的原點一起使用,這就是您要繪製的矩形。

CGSize size = [string drawInRect:rect .... plus your options]; 
CGRect boundingRect = rect; 
boundingRect.size = size; 

[[UIBezierPath bezierPathWithRect:boundingRect] stroke]; 
+0

謝謝!這很好。 – Hahnemann

0

drawinRect不返回CGSize了,所以基於jrturton的帖子,我用這樣的事情避開字符串內容完全抽出一個盒子 -

[str1 drawInRect:rect withAttributes:attributes]; 

CGRect boundingRect = [str1 boundingRectWithSize:rect.size options:NSLineBreakByWordWrapping | NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil]; 
boundingRect.origin.x = rect.origin.x; 
boundingRect.origin.y = rect.origin.y; 

[[UIBezierPath bezierPathWithRect:boundingRect] stroke]; 
相關問題