简体   繁体   中英

Swift VFL to pin an item a fixed distance from superview's bottom margin

so I am doing something super simple, I would like to have an object be a fixed distance from the bottom of its superview's margin. say 20 ios points. I try the following:

  addConstraintsWithFormat("V:|[v0]-20-|", views: nameLabel)

where addConstraintsWithFormat() is defined as following (from Brian Voong's facebook app):

extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerate() {
  let key = "v\(index)"
  viewsDictionary[key] = view
  view.translatesAutoresizingMaskIntoConstraints = false
}
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
}
}

what this does, though, is place the object right next to the top margin of the superview, as opposed to 20 points next to the bottom margin of its superview.

Not really sure how to accomplish what i am aiming for.

The | represents the superview, so you need to delete the first one so that your view is not pinned to the top of its superview:

"V:[v0]-20-|"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM