это мой код для uibutton, который не работает. Я делаю автопрокладку программно, перепробовал много решений в интернете, но это не работает. Есть предложения?
let ButtonSignUp: UIButton = {
let btn = UIButton()
btn.translatesAutoresizingMaskIntoConstraints = false
btn.setTitleColor(.white, for: .normal)
btn.titleLabel?.font = AppThemeFonts.buttonFonts
btn.layer.cornerRadius = 6
btn.setTitle("SIGNUP", for: .normal)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = btn.bounds
gradientLayer.colors = [UIColor.red.cgColor, UIColor.yellow.cgColor]
btn.layer.insertSublayer(gradientLayer, at: 0)
gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0)
gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0)
gradientLayer.locations = [0.0, 1.0]
return btn
}()
ниже показано, как я устанавливаю ограничение в viewdidload
let buttonsView: UIStackView = {
let view = UIStackView()
view.distribution = .fillEqually
view.axis = .horizontal
view.spacing = 10
view.addArrangedSubview(ButtonSignUp)
view.addArrangedSubview(ButtonLogin)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
self.view.addSubview(buttonsView)
let xConstraintButtonView = NSLayoutConstraint(item: buttonsView, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1, constant: 0)
let yConstraintButtonView = NSLayoutConstraint(item: buttonsView, attribute: .centerY, relatedBy: .equal, toItem: self.view, attribute: .centerY, multiplier: 1.75, constant: 0)
let widthConstraintButtonView = NSLayoutConstraint(item: buttonsView, attribute: .width, relatedBy: .equal, toItem: self.view, attribute: .width, multiplier: 0.9, constant: 0)
let heightConstraintButtonView = NSLayoutConstraint(item: buttonsView, attribute: .height, relatedBy: .equal, toItem: self.view, attribute: .height, multiplier: 0.068, constant: 0)
self.view.addConstraints([xConstraintButtonView,yConstraintButtonView,widthConstraintButtonView,heightConstraintButtonView])