Я добавляю UberLo go в строку меню моего приложения, используя ImageView. Однако lo go панорамируется в верхний левый угол ячейки. Я попытался перецентрировать его в ячейку с помощью онлайн-видео. AddConstraintWithFormat работает, но не добавляет ограничение. Кто-нибудь может помочь? Спасибо!
class MenuCell: BaseCell {
let imageView: UIImageView = {
let iv = UIImageView()
iv.image = UIImage(named: "UberLogo")
return iv
}()
override func setupViews() {
super.setupViews()
addSubview(imageView)
imageView.translatesAutoresizingMaskIntoConstraints = false
addConstraintsWithFormat("H:|[v0(28)]|", views: imageView)
addConstraintsWithFormat("V:|[v0(28)]|", views: imageView)
addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1, constant: 0))
addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0))
}
}