Reputation: 145
I just create a app ,that have 3 UIButton
in vertical mode one by one.I add some autolayout to fix my image .but it differ for different simulator device. I create uibutton using story board .And i name it Button1,Button2,Button 3
This is my viewcontrller.swift
class ViewController: UIViewController {
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
@IBOutlet weak var button3: UIButton!
@IBOutlet weak var titleL: UILabel!
I too see some post to solve constraint .Like this code: (for button1
alone here i added )
self.view.addConstraint(NSLayoutConstraint(item: button1 , attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Leading, multiplier: 1.0, constant: 0.0))
self.view.addConstraint(NSLayoutConstraint(item: button1 , attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Trailing, multiplier: 1.0, constant: 0.0))
self.view.addConstraint(NSLayoutConstraint(item: button1 , attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 0.0))
I need to keep my button like this image
Thanks in advance !
Upvotes: 1
Views: 3180
Reputation: 588
Ok so you need to set three button in vertical mode like this.For that you can make use this two tutorial by raywenderlich. In that first tutorial they will explanin about two autolayout method. Like you need they use UIView to explain
Hop after read this sure you will get some idea for your app.
Upvotes: 1
Reputation: 1775
Autolayout is difficult to explain in words but the best tutorial on autolayout I have ever seen is lecture 9 in the most recent Stanford iOS course. Here is a link:
https://itunes.apple.com/us/course/8.-view-controller-lifecycle/id961180099?i=335430612&mt=2
Autolayout starts around minute 22 of that video. I highly recommend it.
Upvotes: 1