Pozwolić przypuszczać Twój UIImageView
dodaje się w górę, jak można umieścić na zdjęciu powyżej, a następnie można dodać ograniczenia programowo jak w następujący sposób:
override func viewDidLoad() {
super.viewDidLoad()
// assuming here you have added the self.imageView to the main view and it was declared before.
self.imageView.setTranslatesAutoresizingMaskIntoConstraints(false)
// create the constraints with the constant value you want.
var verticalSpace = NSLayoutConstraint(item: self.imageView, attribute: .Bottom, relatedBy: .Equal, toItem: self.button, attribute: .Bottom, multiplier: 1, constant: 50)
// activate the constraints
NSLayoutConstraint.activateConstraints([verticalSpace])
}
W powyższy kod I umieścić tylko ograniczenia przestrzeni pionowej, musisz ustawić niezbędne ograniczenia, aby uniknąć ostrzeżenia o tym.
Istnieje kilka sposobów programowego dodawania ograniczeń. W tej bardzo miłej odpowiedzi można przeczytać więcej: SWIFT | Adding constraints programmatically.
Mam nadzieję, że ci to pomoże.
należy również dodać ograniczeń programowo https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy: toItem: attribute: multipiplier: constant: –