In my app i have a UIView i use as a container. It changes its height depending on if shown on a 3.5 inch or a 4 inch screen. I has 4 subviews as shown on the image.
What i want is to have these 4 subviews to have no space between each other and have the same height regardless what height is the view that contains them.
It looks good on this 4 inch screen:
But it looks bad on this 3.5 inch screen:
Thank you for your help!
Zoli
Just add a constrain to the height of the view, it will keep the height static:
Ctrl+click on the top part of the view, go down a bit and release the click, you'll se the option.
Related
I'm creating a scene in XCode in Main.storyboard where the user is able to choose between 5 options (buttons) and when I created the auto layout to horizontally center the buttons, as well as vertically space them 5 pixels apart:
On the 3.5 inch screen, the buttons take up most of the screen
On the 4 inch screen, the buttons take up about 3/4 of the screen
On the 4.7 inch screen, the buttons take up about half of the screen
It makes sense for this to be happening, but I created a #3x, #2x, and normal sized (1x) images using Prepo
The buttons have custom background image properties
How can I get the 4 inch, 4.5 inch, and even 5.5 inch screens on the iPhone to display like the 3.5 inch screen where the buttons take up most of the screen?
Set the following constraints for your buttons.
For 1st button set constant top space to top layout guide (say 20px).
For last button set constant bottom space to bottom layout guide (say 20px).
Set equal heights for all buttons.
And you already have the following constraints.
align buttons horizontally centre
vertical spacing between them is 5px
So now buttons will adjust its height to take up most of screen space.
Try this.
I have 4 items in a UIView which should always fill the UIView for all Screen sizes. It doesn't matter which auto layout constraints I apply, they won't fill the view equally (each item won't have the same width)
Click here for a picture for 5.5 inches iPhones.
And here for 4 inch iPhones.
As you can see, the last icon is not in the view anymore in the 4 inch screen.
How can I apply a flexible, stretchable layout in Interface Builder? Do I have to make a custom View and modify the constraints in code?
I ended up doing it in code. I applied width constraints and changed the sizes in viewDidLoad(). For X-Positioning I just aligned one item next to the other (horizontal spacing).
Ok, so I want the positioning of the items in a view to re centre when going from 4 inch screen to 3.5 inch screen. How do I do this.
I've attached pictures for what it looks like on a 4 inch screen and what it looks like on a 3.5 inch screen.
Image 1: http://i.stack.imgur.com/P2KtI.png
Image 2: http://i.stack.imgur.com/V1TLb.png
So image 1 is the 3.5 inch version and 2 is the 4 inch version. As you can see on the 4 inch screen, all the items in the view are in the centre relative to the height. I want it to be in the centre for the 3.5 inch screen as well. How do I do this with autolayout?
If you're programmatically implementing the objects you could easily change the placement for the screen size based around the self.view.frame.size.height. You could take that information and correctly place your objects in the center by doing some basic math.
If you're using storyboards you can use autolayout to set constraints in IB to have all of the items stay where you want them relative to the screen size. When you select an item on your scene you can easily add autolayout constraints by going to Editor -> Resolve Autolayout Issues -> Add Missing Constraints.
Remember that if you are using storyboard's you can change which screen size you're viewing. In the bottom right of IB there are a selection of buttons and the one on the far left toggles between 4" and 3.5" screen sizes.
I am making the layout of my app comparable with 3.5 inch devices. However, I am confused with Constraints and Auto Layout.
I am trying to make a view always be in the center of two views regardless of the screen size but whenever I do this it always goes behind another view.
The 4 inch view:
The 3.5 inch view:
If someone could help me figure out why this is happening I would be grateful.
You can add a wrapper view (normal UIView is okay), align the top bound with the bottom of "safe", align the bottom bound with the top of the circle. Two constraints should be added automatically. Then put your inner view at the vertical center of the wrapper view.
Your Constraints should be like this
I(any y value you want your UILabel to start at)
I(+30)
UILabel (Safe)
I(+30)
UITExtField
I(+30)
UIView that contains all Number Buttons.
Adjust all accurately that it work in least possible dimensions. i-e 3.5
I'm trying to add an iAd banner which I set just above a UITabBar, and it works perfectly on 4 inch screens, but when I test it on 3,5 inch the banner is totally invisible.
Is there a simple way to fix all the views so that everything will be scaled to the 3,5 inch screen if needed?
I've found a tutorial saying to set the "size" of the "Simulated Metrics", under the Attribute Inspector of the view to freeform, but it doesn't work.
You need to specify constraints for how all of the screen contents moves or resizes and the available space changes. The banner view need to be pinned to the bottom and you will need a view somewhere to be pinned to other views but have a flexible height.