我正在使用UIKit的drawInRect繪製一個字符串。我還想繪製(參見)繪製字符串的邊界矩形(在框中有一個字符串)。這個怎麼做?如何在使用drawInRect時繪製包含字符串的框?
0
A
回答
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
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];
相關問題
- 1. 如何在使用`text`繪圖時包裝字符串?
- 2. 使用熊貓字符串的方法「包含」在包含字符串
- 3. Swift - 使用drawInRect繪製文本:withAttributes:
- 4. 如何在字符串中包含「
- 5. 如何匹配mediawiki框中包含換行符的字符串?
- 6. 如何在BitmapData上繪製字符串
- 7. 繪製字符串的粗邊框
- 8. ggplot2:如何繪製包含特殊字符的列?
- 9. 如何使用包含「在SQL」IN「子句中的字符串
- 10. 如何將字符串轉換爲字符串包含十六進制字符
- 11. 如何使用NSXMLParser解析包含&符號的字符串?
- 12. 如何在JTable上使用RowFilter.dateFilter(如果它包含字符串)
- 13. 如何插入包含「;」的字符串
- 14. 如何插入包含「&」的字符串
- 15. 如果字符串包含'
- 16. 使用PowerShell來替換字符串中包含$的字符串
- 17. 使用PowerShell替換字符串中包含的字符串
- 18. 字符串包含
- 19. 字符串包含
- 20. 包含字符串
- 21. 用BitmapFont繪製字符串
- 22. 如果我的字符串包含'/',如何使用'///'?
- 23. 如何在子字符串包含等號時執行子字符串替換?
- 24. 當字符串包含'{}'字符時不能組合字符串
- 25. 如何從包含「,」的字符串獲取字符串值?
- 26. 如何使用C#在pictureBox上繪製固定字符串?
- 27. 如何在Android中使用Canvas.drawText繪製一個Spanned字符串
- 28. 如何使用.matches字符串中包含。*之間的字符在java中
- 29. 如何在jsoncpp中使用decodeString來解碼包含unicode字符的字符串
- 30. 如何在包含非英文字符的字符串屬性上使用Query.order()?
謝謝!這很好。 – Hahnemann