简体   繁体   中英

Adjusting location of unknown text with rotation

I have an array of strings, example is below but normally, I will read the strings from a JSON file and have no knowledge of their contents.

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"]

I want to plot these on a circle by attaching lines, see image.

围绕椭圆旋转文本 when theta is past pi/2 I need to move the string, otherwise it will be clobbered by the drawing.

I'm not using UIlabels but s.drawAtPoint(CGPoint(x: x + 0.0 , y: y - fontSize*1.5 ), withAttributes: attributes)

  1. How to get the positional offset of an unknown string? Without counting up characters and using font properties.

  2. Is there a way to do this without an if statement?

Using this will get height and width of bounding box of string sizeWithAttributes(attributes)

Then

xOffset = -s.sizeWithAttributes(attributes).width

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM