ios - Positioning two UIButton elements in the main view using NSLayoutConstraint -
I'm sure I'm missing something very simply here. I am working through the documentation about the programs working with the automatic layout and I am trying to follow the instructions for putting two buttons next to each other.
This is my code:
viewDidLoad () {super.viewDidLoad () view.backgroundColor = UIColor.grayColor () var Button1 = UIButton () button1.titleLabel. Text = "foo" button1.backgroundColor = UIColor.redColor () on Button2 = UIButton (function override) button2.titleLabel.text = "bar" button2.backgroundColor = UIColor.purpleColor () view.addSubview (Button1) view.addSubview ( Button2) var binding = [ "Button1": Button1, "Button2": Button2] // raised by this arbitrary ... var opt = NSLayoutFormatOptions.AlignAllTop bridesmaid formatString = "[Button1] -12- [Button2]" var c = NSLayoutConstraint.constraintsWithVisualFormat (formatString, Options: Choose, Metrics: Zero, Thoughts: Binding) view.addConstraints (C)}
When I I get the error:
2014-07-27 01: 41: 43.597 Dynamic Out [2366: 53275] Unable to meet the barriers at the least, at least the following list may be One obstacle is the one you do not want. Try it: (1) Look at each obstacle and try to figure out what you do not expect; (2) Get the code that connects unwanted obstacles or obstacles and can fix it. (Note: If you are looking at the NSAutoresizingMaskLayoutConstraints that you do not understand, refer to the documentation for the translation of UIView Properties. Advanced microscope consultants ("& lt; NSLayoutConstraint: 0x7be6fda0 H: [UIButton: 0x7be69a00] - (12) - [UIButton: 0x7be6d200] & gt; "" & lt; NSAutoresizingMaskLayoutConstraint: 0x7be74c20h = - & amp; V = - & amp; UIButton: 0x7be69a00.midX ==> "" & lt; NSAutoresizingMaskLayoutConstraint: 0x7be74d40h = - & amp; V = - & amp, H: [UIButton: 0x7be69a00 (0)] & gt; "" & LT; NSAutoresizingMaskLayoutConstraint: 0x7be723f0 h = - & amp; V = - & amp; UIButton: 0x7be6d200.midX == & Gt; ")
I'm sure if more This error message will be useful, but I'm not sure where to start parsing it. I am doing wrong here?
If you want to add a lack of programming to stop the program, then translateautorisingmask inconsurnants
to false
Use the code below to drag this button and use titleLable.text
button Instead of using 1 setTitle ("foo" forState: UIControlState.Normal)
is the method to set the title for this button
viewDidLoad () override the function {View.backgroundColor = UIColor.grayColor () on Button1 = UIButton () button1.setTranslatesAutoresizingMaskIntoConstraints (incorrect) button1.setTitle ("foo" forState: UIControlState.Normal) button1.backgroundColor = UIColor.redColor () Button2 = UIButton () Button2.setTitle ("bar", forState: UIControlState.Normal) button2.backgroundColor = UIColor.purpleColor () button2.setTranslatesAutoresizingMaskIntoConstraints (false) self.view.addSubview (Button1) self.view.addSubview (Button2) binding = [" Button1 ": Button1," Button2 ": Button2] Selects arbitrarily on this ... = NSLayo UtFormatOptions.AlignAllTop // raised formatString = "[Button1] -12- [Button2]" on C = NSLayoutConstraint.constraintsWithVisualFormat (formatString, Options: Choose, Metrics: Zero, Thoughts: Binding) view.addConstraints (c)} < / Code>
Comments
Post a Comment