2011-09-14 6 views

答えて

2

drawInRect UIKitメソッドは、描画された文字列のサイズであるCGSizeを返します。 drawInRectに渡されたCGRectの起源と一緒に使用します。これは描画したい矩形です。

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

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

感謝を!これは素晴らしいです。 – Hahnemann

0

drawinRectはそうjrturtonのポストに基づいて、私は文字列の内容を中心に、正確に描かれたボックス取得するには、このようなものを使用し、もうCGSizeを返さない -

[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]; 
関連する問題