0

So I'm trying to add constraints programmatically:
I'm simply adding two constraints and Xcode has started to show me:

centerXAnchor is only available in iOS 9.0 or newer

Here is my code:

var constraints = [NSLayoutConstraint]()

let centerImageX = imageView.centerXAnchor.constraint(equalTo: footerView.centerXAnchor)

let centerImageY = imageView.centerYAnchor.constraint(equalTo: footerView.centerYAnchor)

constraints = [centerImageX,centerImageY]

NSLayoutConstraint.activate(constraints)

One thing which I want to share is probably unbelievable that couple of days back I wasn't getting any error message.

My Xcode version is 8.2.1.

Also my deployment target is 8.0 and above. So, if anyone could tell me or can convert or translate the same code for iOS 8.0 that would be awesome!

Mr. Xcoder
  • 4,719
  • 5
  • 26
  • 44
Yash Bedi
  • 1,323
  • 17
  • 25

1 Answers1

1

This should do the same job:

self.view.addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerX, relatedBy: .equal, toItem: footerView, attribute: .centerX, multiplier: 1.0, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerY, relatedBy: .equal, toItem: footerView, attribute: .centerY, multiplier: 1.0, constant: 0))
James P
  • 4,786
  • 2
  • 35
  • 52