Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 6.4 - Unable to set constraints on Views or ... anything

There are many guides out there that talk about auto-layout such as: http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1

Now constraints don't seem to be super complicated except that when it comes to trying to set them on a UIImageView within a ViewController, With "Use Auto-Layout" ticked, I can't for the life of me set any constraints as when I click any of the three buttons used to achieve this, all the options for setting constraints is greyed out.

I'm sure this is something simple... little help?

I've found something in reference materials: "Constraint options that require multiple elements are disabled if you have only a single element selected." but in none of the guides do I have to have more than the UIImageView selected to set constraints.

Edit: added images:

ContraintsGreyedOut1of2

ContraintsGreyedOut2of2

like image 462
Lance Avatar asked Sep 11 '15 01:09

Lance


People also ask

How to edit/remove constraints in Xcode project?

If you want to remove one constraint, just select it and press delete key in keyboard. If you want to edit one constraint value, just select it, and then edit it in Attributes Inspector pane ( How To Display Xcode Library, Assistant Editor, Inspectors Window ) at Xcode project right side.

How to use Swift constraints to constrain UI component?

How To Use Swift Constraints To Constrain UI Component. There is an auto-layout menu bar at the right side of the View as device simulator icon list, it provides five buttons for you to constrain UI components or align multiple UI components. Below are the steps about how to use it.

How to add constraints to a button in auto layout?

You have two methods to add constraints to it. Select the above button, click the Add New Constraints icon ( ) on the above auto-layout menu bar. Then it will popup the Add New Constraints dialog where you can specify the button constraints value in it.

How to add constraints to a button in a storyboard?

Add a UI component ( a button ) to the Main.storyboard scene. Change button background color to green and button text color to red, also change the button text font. You have two methods to add constraints to it. Select the above button, click the Add New Constraints icon ( ) on the above auto-layout menu bar.


2 Answers

In my case, Xcode 11.2 somehow set layout property of my UIButton tranlates mask into constraints. So I changed it to automatic from size inspector and it is fixed.

like image 75
atalayasa Avatar answered Sep 28 '22 09:09

atalayasa


This is because you remove root view from view controller. When you add UIViewController to storyboard you can see this:

enter image description here

If you delete this view and add UIImageView you see this:

enter image description here

enter image description here

So add UIView as root and UIImageView as single subview of root view. And then you can play with constraints:

enter image description here

like image 35
rkyr Avatar answered Sep 28 '22 09:09

rkyr