【问题标题】:Adjusting location of unknown text with rotation通过旋转调整未知文本的位置
【发布时间】:2015-04-29 22:38:39
【问题描述】:

我有一个字符串数组,示例如下,但通常情况下,我会从 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)

  1. 如何获取未知字符串的位置偏移量?无需计数字符和使用字体属性。

  2. 有没有办法在没有 if 语句的情况下做到这一点?

【问题讨论】:

    标签: ios swift uikit


    【解决方案1】:

    使用这个将得到字符串边界框的高度和宽度 sizeWithAttributes(attributes)

    然后

    xOffset = -s.sizeWithAttributes(attributes).width

    drawAtPoint(CGPoint(x: x + xOffset , y: y + yOffset ), withAttributes: attributes)

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 1970-01-01
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多