0

I have a problem where I am trying to center a UILabel within a programmatically generated circle (CAShapeLayer). The problem is that CAShapeLayer is not extended from UIView or NSLayoutGuide, so I am getting a runtime error with the following segment of code:

let circlePathLayer = CAShapeLayer()

let xConstraint = NSLayoutConstraint(item: statusLabel, attribute: .CenterX, relatedBy: .Equal, toItem: circlePathLayer, attribute: .CenterX, multiplier: 1, constant: 0) //Cannot set circlePathLayer

Is there an easy way to fix this?

ML.
  • 589
  • 1
  • 9
  • 33
  • 'NSInvalidArgumentException', reason: '*** +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: Constraint items must each be an instance of UIView, or NSLayoutGuide.' – ML. Jan 27 '16 at 04:56
  • Basically, CAShapeLayer is not a UIView or NSLayoutGuide. I don't know of any other ways to programmatically set constraints. – ML. Jan 27 '16 at 04:57
  • moved the Constraint code from the initWithNib method to viewDidLoad –  Jan 27 '16 at 05:00

0 Answers0