How to align centerXAnchor constraint in previous versions iOS?

//align to horizontal center:
@discardableResult func alignXCenter(to anchor: NSLayoutXAxisAnchor, padding: CGFloat = 0) -> NSLayoutConstraint {
    //enable auto layout (if not enabled so far:
    if(self.translatesAutoresizingMaskIntoConstraints == true) {
        self.translatesAutoresizingMaskIntoConstraints = false
    }
    let centerXConstraint = self.centerXAnchor.constraint(equalTo: anchor, constant: padding)
    centerXConstraint.isActive = true //centerX
    return centerXConstraint
}

I found that this options is available only on the latest iOS (newer than v11.0):

if #available(iOS 11.0, *) {
    btn.alignXCenter(to: view.safeAreaLayoutGuide.centerXAnchor)
} else {
    // Fallback on earlier versions
   //What to use here for older iOS ??? <----------------- question
}
Terms of Service

Privacy Policy

Cookie Policy