ビューコントローラーの右側に添付された一種の「パネル」として機能するビューを作成しようとしています。ビューコントローラーの余白にバインドされた制約をプログラムで作成する
、それはしかし、私はちょうどそれが右のように見えることはできません300
の静的な幅で、親ビューコントローラの末尾、上、下の余白にバインドされていることを、私は」制約を破るか何かをすると、xcodeは私に違法だと伝えます。
私は間違っていますか?ここで
コードがコントローラに
let myView = UIView()
view.backgroundColor = UIColor.redColor()
self.view.addSubview(view)
let topConstraint = NSLayoutConstraint(item: myView,
attribute: .Top,
relatedBy: .Equal,
toItem: self.topLayoutGuide,
attribute: .Bottom,
multiplier: 1,
constant: 0)
let trailingConstraint = NSLayoutConstraint(item: self.view,
attribute: .TrailingMargin,
relatedBy: .Equal,
toItem: myView,
attribute: .Trailing,
multiplier: 1,
constant: 0)
let bottomConstraint = NSLayoutConstraint(item: self.bottomLayoutGuide,
attribute: .Top,
relatedBy: .Equal,
toItem: myView,
attribute: .Bottom,
multiplier: 1,
constant: 0)
let widthConstraint = NSLayoutConstraint(item: myView,
attribute: .Width,
relatedBy: .Equal,
toItem: nil,
attribute: .NotAnAttribute,
multiplier: 1,
constant: 300)
self.view.addConstraints([trailingConstraint])
view.addConstraints([topConstraint, bottomConstraint, widthConstraint])
なぜVisual Format Languageを使用しないのですか? – Eendje