[英]Adjusting location of unknown text with rotation
我有一个字符串数组,下面是示例,但通常情况下,我将从JSON文件中读取字符串,但不知道其内容。
let SNPJSON:[String] = ["really long text 1","really long text 2",
"really long text 3","really long text 4","really long text 5",
"really long text 6","really long text 7","really long text 8"]
我想通过附加线将它们绘制在一个圆上,参见图像。
当theta超过pi / 2时,我需要移动字符串,否则它将被图形破坏。
我没有使用UIlabels,而是s.drawAtPoint(CGPoint(x: x + 0.0 , y: y - fontSize*1.5 ), withAttributes: attributes)
如何获得未知字符串的位置偏移? 无需计算字符和使用字体属性。
没有if语句,有没有办法做到这一点?
使用它会得到字符串sizeWithAttributes(attributes)
的边框的高度和宽度
然后
xOffset = -s.sizeWithAttributes(attributes).width
和drawAtPoint(CGPoint(x: x + xOffset , y: y + yOffset ), withAttributes: attributes)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.