簡體   English   中英

旋轉調整未知文字的位置

[英]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)

  1. 如何獲得未知字符串的位置偏移? 無需計算字符和使用字體屬性。

  2. 沒有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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM