iOS: autolayout for multiple button - ios

In my app I have a view for 4 inch screens in this way:
And then I want to reduce the size of my buttons when the app is running on an iPhone with a 3.5 inch screen, so I set my layout in this way:
but finally I obtain a view in this way
In this way the size of my button are ok but they are not aligned, so in this situation, what's the way to have aligned buttons?
thanks

Hi as per your question i've created demo similar to the layout for which you need the controls need to set. I've added images for single control and made video this using multiple controls to set the layout which you retrying to set.
link: https://www.youtube.com/watch?v=Nl2iMF0yKW8&list=PLXCowKcXAVgrxHKLWTa4HxNPrSmTj3D-_
Hope this will solve your issue.

I may not comment till I 50 posts, so here is the link. I had like the same problem some days ago. Just put all those in a parent view and center the parent view.
Link to my question/answer:
Top constraint won't get less with auto-layout

Related

swift 4 and Xcode autoLayout and UIImageview as Button

I am working on auto layout and making those UIIMages as Button.
I would like to make those button to be clicked and switch the images
as well as showing some words in the label.
In this case what should I do?
In addition, as it is shown, the auto layout ratio is different only from the iPhone SE. In. this case What should I consider?
Many thanks,
The first thing you need to learn is auto layout. Start with basic Always go with Apple's doc first
This one I likes he is good and you will also find how to use buttons as image view, using card game example, check other tutorials also very helpfull.
Stanford university autolayout by Michel Deiman
As far, your question just gives your label Horizontal in the container constraints(open storyboard in the right bottom third from last (allin) click on it popUp will open), and 20 bottom to the buttons and it will be in the centre. Every elements need x,y height and width so it knows exactly where to place, so you also need to give constraints to the buttons, Learn stackView to understand how to place your button without giving many constraints to each button and stack view will handle it for you, try hide and show to one of the button and magically stack view will adjust all adjustment. I suggest before staring Do read apple's doc first.
And Your question is too broad to answer, so read and try adding different constraints based on your need and ask a specific question(after trying by yourself) like why this label getting cut what constraints should i add so people know exactly what you want to achieve, people are always ready to help, just ask the right question.
happyCoding

Buttons and Labels Not in Place

I am asking perhaps one of the easiest questions lol but just could not figure it out.
I have some view controllers created based on the screen size of iPhone 7, but when I change devices to iPhone 7plus and iPhoneSE, my labels and buttons were all misplaced...
I have uploaded what they look like in different devices, can somebody please help?
WhatItLooksLikeOniPhone7
WhatItLooksLikeOniPhoneSE
To keep the UI elements at a defined place you need to something that will keep the elements at their position. And hence you need to use autolayout.
Autolayout is basically a constraint based system which will layout the ui elements.
There are many tutorials available.

Different iOS devices size programming approach

I am starting a new project which should be working on every iOS device size possible.
The project is rather simple. The main view will be a scroll view and it will hold a '+' button (where it says 'button' in the image) in the top right corner. (It does not really matter, I'm just trying to give the general idea of what I'm trying to understand and implement.)
A small example:
What is the right approach for this kind of problem?
Should I create a different storyboard for each device?
Should I start creating an adjustable scroll view that will hold the needed buttons with some constraints (if at all possible)?
I have read this tutorial:
auto layout
which explains the auto layout nicely, but does not mention the issue I'm trying to figure out.
Any thoughts?
Use AutoLayout and position your views relative to one another (so no x pixels spacing between views). Make only one storyboard for all devices, when a different view should be loaded on another device (like a completely different layout), select the appropriate size class and adapt the views and constraints.
Then it will be recalculated on every device.
The storyboard has a preview section where you can choose a device to simulate the view on.

Change view sizes inside UIScrollView using Autolayout

I'm trying to create a 3x3 menu, based on a grid of buttons, and I'm facing a lot of problems trying to adapt it to different screen sizes.
Since I want my menu to be equally spaced on the screen (using autolayout tricks on the Storyboard), I have created a custom class with this menu that i'm adding to the center part of the main controller view. The problem is that the menu doesn't fit in small screen (3,5" screens).
Trying to solve this problem, I have created a scrollView in the main screen to add the menu and be able to scroll in small screens.
The problem is that since the view I'm loading in the scrollview, automatically fits to the size of the container (in this case the UIScrollView), only a small part of the menu is appearing in the 3,5" screen, without the option of scrolling (In bigger views it appears equally spaced and everything appears correctly).
How can I solve this UIScrollView problem? Or there is a better solution for this problem?
p.s: I'm sorry, but I don't have enough reputation to add images :(
Uiscrollview with autolayout has some pain into it.
You need to place you're inner views so the scrollview Will be able to understand the contentsize it should use.
You can find more detailed info here
http://infinite-edward.tumblr.com/post/66865604683/uiscrollview-contentsize-and-autolayout-gotcha

Storyboard layout not correct on iPad 2

I am trying to lay out objects on a Storyboard using the interface builder yet when I run the app on an iPad2, the layout is being messed up and objects are not appearing where they should. All the objects are there but they are being moved horizontally and not the same number of pixels! For instance, I have two ImageViews overlayed on one another (one is 100x100 and one is 75x75 centred within) but when the app is run on the iPad, they are both being moved horizontally across the screen by different distances!
I'd like to add screenshots but unfortunately I can't for privacy reasons.
I know it's vague but does anyone have any ideas on where to start looking to fix this?
Thanks.
I had this problem too when I was first making an iPad app.
Try fiddling with some of the 'struts & springs' of the interface elements in the storyboard. To do this, select some of the interface elements, then on the right panel go to the size inspector and try some things with the 'Autosizing' rectangle.
Hope it helps!

Resources