Hiding a view based on screen size. - ios

I tried to search but could not find anything. Or could not ask the right way... =\
Anyway I have a simple UIViewController that no mater the screen size things look great. I was asked to add some text to it and this is where the problem arises. On 4.7 and 5.5 screens I have enough room but not on a 4 inch screen. Playing with size classes I can not find a way to indicate a 4inch or smaller screen only. I want to NOT show the UILabel on a 4 inch screen and DO show it on the other larger two. I'm sure this could be done in code by [lbl setHidden:YES] if the screen size is less that x. Is there a way to accomplish this in Interface Builder so I am able to show the boss the layout without having to run it in different simulators or devices? I.E. using the preview editor.

You should play around with Installed property in Attributes Inspector, but you cannot hide for only 4 inch screen, because wCompact and hAny is for 3.5, 4, 4.7 inch, wCompact and hRegular is for all iPhone portraits, thus you will hide the label for 3.5, 4, 4.7 inch if you uncheck Installed property for wCompact and hAny. For such behaviour, you should do by code.

Related

Is using constraint/auto-layout on iPad a mandatory?

All iPad screens, iPad 1, iPad 2 ... , iPad Retina and Mini iPad have the same screen ratio. width/height or height/width or width:height
So, Why do we need to use constraints for the iPad views?!
I also believe that in interface builder when you select the view controller, you can view it as iPad or iPhone. there is many iPhone options but only one iPad option. you can do that by clicking the size drop down list in the Attributes Inspector.
Is there any of the iPad screens that have more or less screen points comparing to others? "Screen Points" not "Screen Pixels" if yes, Which one is that?
You don't have to use auto layout, but it's a good idea to. Once you understand it it's faster to work with, more flexible and very powerful for animations. You should also consider device rotation and usage for things like multi-tasking (ios9, use size classes too).
If you Design your Screens in Width Any / height any than your design will run on any iphone and Ipad Screen with autolayout. And it's a good practice too. if you want any change for iphone / ipad screen than you can remove that constraint for particular devices.add particluar constraint for particular devices.

View goes out of order when change screen size ios

I am developing an app for ios. When I build it on simulator for 3.5 inch retina it works fine because I designed it for that in Interface Builder. But when I change simulator from 3.5 inch to 4 inch, components goes out of order. Here I have share snapshots:
3.5 Retina Image
Table view is highlighted in red box.
Retina 4 inch
Size of table view is increased but button is at old position. This is my problem.
Any suggestions?
Follow steps:
1. Go to your xib file
2. Select UITableView control from XIB
3. Then remove auto resizing mask from right side section
refer screen shot

Auto layout 3.5 - 4 inch screen as well as ipad mini to normal?

I know to go from the 3.5-4 inch screen with the app you create you have to use auto layout to make it nice on both screens. I was wondering if you had to do the same for the ipad mini - ipad? When i go into the attributes inspector there is no ipad mini choice on the view controller like there is for the 3.5 inch display. With the ipad story board is it a one size fits all type of thing or should I still use auto layout?
Thanks
Shen Hutah
The reason for resizing with the 3.5-4 inch screens is due to a changed aspect ratio. With iPad and iPad mini, they have the same aspect ratio (4:3), so the screens are functionally the same. Unless you're altering the view based on autorotation, there's technically no need to use autolayout.

Displaying different images for iPhone 4 & 5

This seems to be an interesting problem that I'm getting. I'm developing an iPhone app for iOS 6+ devices and optimizing the images for both iPhone 4 & 5. Now I have implemented this into my project: Xcode 4.5 background image iPhone 4, 4s, 5
The problem is in interface builder I'm designing the UI with the iPhone 5 screen, so the UIImageView is 320x568. But when I test on iPhone 4, the image is being stretched and looks terrible. However, the specified image for the iPhone 4 screen is displaying, i just want its dimensions to be 320x480
Hope someone can help!
From the inspector view in the interface builder, you can edit the stretching behavior of the view when the size of the super view changes. You can click the red arrows inside the square to control that.
Also I suggest that you check UIView contentMode. You can edit that from the inspector view in the interface builder "third tab from the right.
In the UIImageView's inspector, try playing with the Mode property. The Aspect Fill or Aspect Fit may get what you're looking for to handle the different screen sizes.

How to make controls in view not overlap if built by Interface Builder for Xcode 4.5 and iPhone 5?

I am using Xcode 4.5 and iPhone 4 and 5 simulator, and the Interface Builder would add a UIButton in the top half of the screen with a top constraint, and add a UIButton in the bottom half of the screen with a bottom constraint.
It works fine on an iPhone 5 simulator, but on the iPhone 4 simulator, the buttons can overlap, or the bottom button may even get positioned above the top button.
I think it is due to the constraint, such as the bottom button "must be 250 points away from the bottom margin". I can't delete the constraint, and if I change it to "250 points or less", it won't work, if I change it to "250 points or more", it won't work either.
Is there a way to:
1) Make it have no constraint, but just position at absolute x and y? (or what about the spring in the past, so that everything is more spaced out in iPhone 5?)
2) Make the NIB into a one for iPhone 4 and 4S only, so that the app works well on iPhone 4 and 4S and just "black barred" on the iPhone 5.
3) Make it work well on iPhone 5 and work well on iPhone 4 as well?
If you know solutions to only (1), (2), or (3), above, please give it regardless, as it is still a viable solution for the transition period.
It is actually very easy to reproduce: Create a simple Single View app using Xcode 4.5, and drag one button just above the center point of the screen, and another one just below the center point of the screen. Then run it on the Simulator. On iPhone 5, it is:
And now stop the app, and change the Device in the Simulator to iPhone 4S (3.5 inch Retina). If you don't stop the app first, the Simulator can crash. Now run the app again, and the buttons will overlap:
I had the same problem, and it was due to a wrong settings for autosizing. To change the autosizing, click on the control in the interface builder, go to the size inspector.
Notice the bold red I's in the autosizing grid, they control placement when the screen is resized (like when going from iPhone 3GS to iPhone 5.
I think it will work best for you if you make your autosizing look like this:
I'm not sure, since I haven't used constraint-based layout (and won't until we drop support for iOS 5). Traditional NIB-based autoresizing will do absolute coordinates.
You can't do that for just one screen, as far as I know — you can disable it for your whole app by removing Default-568h#2x.png.
I'd go for programmatic layout, or if you want the easy way (which will be a pain to maintain), different nibs for different screen sizes. Note that you'll want to correctly handle the in-call status bar too...
EDIT: Put the two buttons in a container view and make the constraint center the container inside its parent? It won't adjust the spacing between buttons, but should look okay on both devices.
Select your buttons and add "vertical spacing" constraint for them. And set "less than" for top/bottom margins.

Resources