making buttons with the same spacing by giving Autolayout constraints - swift

I gave constraints to the buttons.
enter image description here
Hello, I was working my app on iPhone 11 Pro max in the storyboard, and when I runt it on (iPad 7 Generation), It has much more spacing between the last button and the leading side of the view.
enter image description here
So, I gave the trailing space to the container, and it looked this in the storyboard
enter image description here
on the iPad 7generation simulator, it looked this way.
enter image description here
it's got much more spacing between the 3rd button and the last button. How can I make the buttons align with the same spacing?

The StackView suggested by Steve is a nice solution. Or try the snippet below if you want to make it work without a StackView.
To evenly spread buttons horizontally across the screen use the following, an example for 3 buttons:
"H:|[spacer0(>=0)][button0][spacer1(==spacer0)][button1(==button0)][spacer2(==spacer0)][button2(==button0)][spacer3(==spacer0)]|"

Related

Storyboard layouts flush with edge of screen, but shows gap in actual iPhone 7 Plus

I have an iOS app coded in Swift and using storyboards. There's a "header bar" at the top of the view controller in the storyboard that should be flush with the left/right edges of the phone:
This behaves as expected in iPhone 6s. However, in the iPhone 7 Plus, it somehow shows a tap of maybe 2 millimeters on the screen, as if the autolayout does not work. According to autolayout, the leading space is -16. Setting it to 0 does not fix it.
Is there something I'm missing on autolayout that makes it work on all devices without showing gaps?
This is a bad way to give the constraint. You have given the constraint to the margin instead of the edge of the screen. Hence, it works fine in 6s but not in any plus device. Remove the constraint and re-apply them with Constraints to margin OFF.
And ya one more thing, when you give constraints with Constraints to margin off, make sure you give the constant as 0.0 instead of -/+16.0

Autolayout - How to Change width spacing between iPhone 6 and Plus

Ok, I have been pulling my hair out for a few days now and thought I would ask the community how to deal with width sizes or the gaps between buttons in xcode 6.4 or 7 (tried them both).
Ideally I want 2 buttons near the bottom and they need to scale properly based upon iPhone portrait mode.
I have added the 1x, 2x, and 3x pngs of the button to the asset system and my auto layout is set for wCompact hRegular which from what I understand allows you to target all iPhone devices in portrait mode.
So after adding my buttons I had it do add missing constraints which added a few and seemed to work pretty good but the issue im running into is the gap spacing between the 4.7 inch and 5.5 inch and how to adjust each one of those separately in interface builder if possible.
See the image below where I outline the gab space and its quite huge for the 5.5 inch.
Also it would be awesome if I could use bigger images for the bigger phone but thats another subject I guess.
Since I cant post images here here is the link to the story board
Take a look at this repository..
https://github.com/mahesh-agrawal/Test-Autolayout-Buttons-Spacing
i have added required constraints to make the gap between the buttons dynamic for all devices. also i have made the width and height dynamic by giving proportional width height.
I have taken two views and given them horizontal spacing 0 and equal width and leading and trailing required for each. and then i have taken two buttons in each and managing width of button with proportional to the views so they will increase accordingly and also the gap will increase accordingly. Test in all devices.

Interface design in iPhone and iPad using Autolayout?

I am developing one application to support both iPhone and iPad. i am using Autolayout for interface design in universal storyboard. i have two textFields and one button . i am adding layout constraints for my components like this( and ). finally my iPhone screen looking like .This how exact i need . But if i run the app in iPad2 the screen is looking like below image . Here textiles and button Width is changing Based on screen size but Textfields and button Height not changing based screen height?. Can anybody tell me how to solve this. I am using Autolayout first time and struggling since morning?
Okay so you have two options here-
1. Under textField, choose the border style I'm attaching below. Then you can change the height of the textField, in the storyboard itself. When you constraint your view, then just don't specify a fixed heigh constraint, and everything should work okay.
2. If you use a textField, then you can just resize it to your needs, and then implement the same constraint specs. But, I personally like textFields more, because they give you options like letting the user enter Secure Text, among other options.

iPhone 5 4 Inch Screen Update

I'm updating my app for the iPhone 5. Now I've read the topics about setting the Autosize Property and I've done that.
My question is regarding some of my elements. The interface of the app is really simple. It uses a pre-defined apple background (no custom images), and has 4 labels and a Information Button.
Two of the labels are fine but the other two and the button are aligned with the bottom of the screen, but with Auto-Sizing it creates and 1/2 inch of background between them and edge of screen.
If there any way to make them stay at the bottom of the screen like that but without having to create a whole new view for iPhone 5, with them positioned right and them programmtically select it when needed, as that is a slightly too complex way for the sake of two labels and a button.
EDITED
Here is some screenshots.
Should look like this (iPhone 4S 3.5 Inch Screen)
linky
Does look like this (iPhone 5 4 Inch Screen)
linky
To get the expected behaviour while using Autolayout, in Interface Builder, you need to select the two labels in the bottom and then go to
Editor -> Pin -> Bottom Space to Superview
This will make sure that the bottom spacing is as expected.

button autoresize

Can anyone help me with the small buttons/icons used within the iphone apps. I am fairly new to the app world and trying to make some buttons(viz the tick box) for my app. I am not sure if we should start with a 50X50 and autoresize in the app or just have a 20X20 which exactly fits the space...
Any help on this is appreciated..
According to Apple, buttons should be at least 44px wide, and 44px high (unless they're by themselves with nothing near them, in which case 22px high). If you're laying out buttons in IB, I'd say get them placed correctly, and set their 'springs and struts' to autosize for you.
Try to do like this,
Put 50*50 button that you need in your project ,and add an image to your interface builder,
select the image that you put recently in Button attributes and select button size by ctrl+3
and set it to 20*20 it works ,it works for me also...