0

When i use CATextLayer in swift 5, i align it to center by using Horizontal alignment modes follow here but it cannot align to center. Here is some of my code

myLabel.textAlignment = .center

textLayer.frame = myLabel.bounds;
textLayer.alignmentMode = CATextLayerAlignmentMode.center

But when i run on ipad pro, i set position x to 500 and it moved to center

textLayer.position = CGPoint(500,20)

But it's not exact and i don't know the reason why it is. So how can i align the CATextLayer exactly to the center as the center Label text?

1 Answers1

0

I don't know what is textLayer in your code but if you want use CATextLayerAlignmentMode you can set it to your label

  myLabel.textAlignment = CATextLayerAlignmentMode.center
Masoud Roosta
  • 455
  • 9
  • 19
  • Cannot assign value of type 'CATextLayerAlignmentMode' to type 'NSTextAlignment' myLabel.textAlignment uses NSTextAlignment, so myLabel.textAlignment = NSTextAlignment.center. And... textLayer.alignmentMode = CATextLayerAlignmentMode.center – Nguyen Thanh Tai Feb 19 '20 at 13:18