1

I am trying to use Auto Layout on multiple buttons and features on my Xcode application, however when I try to auto layout one of the buttons the size of it changes

As shown here: https://i.stack.imgur.com/FCWLJ.jpg

I have used this on labels and sometimes it doesn't change its size but on others it does.

How can I stop this from happening?

Thanks

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Alex Marchant
  • 570
  • 6
  • 21
  • make sure you clean up all the constrains before start – Mohamed Helmy Jul 02 '17 at 07:16
  • So far from the image you have just mentioned the position of the button, hence it lays out according to your position and some default size. But when you will provide its height & width or trailing & bottom, then in that case it won't change its size as changing now. – Ishika Jul 02 '17 at 07:52
  • I have done something very similar in my last project. Will post an answer, if you are not satisfied with Lawliet's answer – Dark Innocence Jul 02 '17 at 08:01
  • @DarkInnocence if you could that'd be perfect – Alex Marchant Jul 02 '17 at 14:47

3 Answers3

1

Add width and height constrains to get your desired button size.

enter image description here

Lawliet
  • 3,438
  • 2
  • 17
  • 28
  • I tried this however I need the buttons to change with the size of the screen otherwise they will overlap and be unusable – Alex Marchant Jul 02 '17 at 14:47
0

For Xcode 9, Swift 4, LayoutGuides are deprecated. If you are using Swift 3, I would recommend just using Auto-Resizing masks to prevent any issues when iOS 11 hits. Constraints will continue to work when using them for subview objects when contained in a parent view. The documentation states that it has been deprecated for iOS 7-11; however, I used the layout guides all throughout iOS 10 and never had any errors or warnings. Warnings are occurring in iOS 11.

See the documentation here: https://developer.apple.com/documentation/uikit/uiviewcontroller

See image here: Death to Layout Guides

Mark Filter
  • 353
  • 5
  • 8
0

Firstly Clear All Constraints as applied Before. Give the Constraints as Follows:- 1) Leading 2) Top 3) Aspect Ratio 4) Equal Width to Superview :-Suppose your Button width is 100 and If your iPhone size is 5,5S then equal width:- Multiplier should be 100:320

So ,it will be dynamic when the device size is change at that time the buttons size also according to device

Hemanshu
  • 68
  • 1
  • 7