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.
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.
What i need is to develop View and want it sub views (button, images, label) to get resize according to the size of screen.
Programatically and with the help "Struts and Springs", i am able to fulfil my requirement by unchecking the autolayout functionality and applying struts and springs with some codes for logo to get resize:
if (iPhone4Or5oriPad==5)
{
self.imageLogo.frame = CGRectMake(TSImage_X_Co_ordinator, TSImage_Y_Co_ordinator, TSImage_WIDTH, TSImage_HEIGHT);
}
I want this to be simple i.e by applying constraints let all subview get resize to get same look and feel for 3.5 and 4 inch screens.
When i use Autolayout this is what it appears for 4 inch screen which is upto my requirement:
But The issue is with its appearance in 3.5 inch screens.
Then i applied constraints to all the subviews.
After applying constraints on 4 inch screen which is ok:
After applying constraints on 3.5 inch screen (Image logo get press more than needed):
Please note via coding and "Struts and Springs", i am able to develop same UI for 3.5 and 4 inch screens. I am eager to know: is their better way that i select all my subviews and apply some constraints and i get the same look and feel for 3.5 and 4 inch screens or is their any better way to do this?. Thank You
select the Image View and then under Attribute Inspector change Mode to Aspect Fill.
I have some pretty basic UI in my app.
Originally, on 4 inch display it looks like this:
But when I switch to 3.5 inch in story board,
the image view seems to change height,
and other controls remain on the same positions (which is what I wanted).
On 3.5 inch:
I don't want the image view to change size when on 3.5 or 4 inch mode,
how to achieve this?
Since this is somewhat easy UI, I was thinking to avoid using auto layout.
If objects remain on the same place, and keep sizes, when switching between
3.5 and 4 inch screen, I should be OK, because I can fit this UI both
on smaller and wider screens.
Hm, you can resize elements with this: photo
If you want the image size to remain untouched, and you are using autolayout, simply pin width and height in storyboard by selecting the image view and then adding the constraints like this (your numbers will be different):
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.
I am try to develop an application involving text views. If I use the 4 inch size, it goes out of the screen on 3.5 inch devices. If I change the size to 3.5 inch, fix it and change it back to 4 inch, there is this big, ugly gap above the text view.
I think the solution to this problem is multiple view controllers. One for the 3.5 inch and one for the 4 inch. But how would I do this? I am using Xcode 5, developing for iOS 7 and testing on an iPhone 4.
Thanks,
Romejanic
You dont have to use two view controllers. All you need are some Auto Layout Constraints or autosizing mask to resize your view for different screen sizes. Below are some helpful links.
Tutorial about auto layouts:
Part 1: http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
Part 2: http://www.raywenderlich.com/20897/beginning-auto-layout-part-2-of-2
Working with Constraints in Interface Builder
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraints/WorkingwithConstraints.html#//apple_ref/doc/uid/TP40010853-CH8-SW1
Apple Auto Layout Guide https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html
A similar question about how to set auto layout constraints for 4 and 3.5 inches screens
Resize view with Auto Layout between 3.5 and 4 inch form factor
If you are using .xib to create your UI then in the size inspector there is an Autosizing feature. You can hold the lower and upper bound for the text view and stretch the text view,i.e, click on the vertical arrow in the middle of the box. This will auto resize your text view according to your device height.