I'm attempting to build a view (iPhone only, portrait view only) using adaptive layout. It should all be on a single screen (ideally no scrolling). I've managed to get it working (reasonably) for the iPhone 5 - 6+. However, my issue comes with the 4s.
I'd like, on the iPhone 4s to have the center image go away, which I thought I could use size classes, but it doesn't seem so for the various iPhones in portrait mode (only if I switch orientation).
Additionally, I'd like there to be more padding between all the elements on the 6+ while spacing remains the same on the 5 and 6.
No matter what sizes all iPhone in portrait mode is regular height compact width so size class won't help you here.
To change padding constraint
make the ones you want to change IBOutlets
and in viewDidLoad for example change the NSLayoutConstraint's constant value based on screen height.
For iPhone 4S you can
hide the center imageView
deactivateConstraints all it's constraints
and activate new constraint between the view above imageView and below imageView if needed
Related
I had an application which is used for portrait only iphone.So i set the size classes to compact width and regular height as suggested.But when i am adding an imageview which is 400*800 and its 2x,3x its not showing properly in iPhone 4s.But it is not showing correctly in 3.5 inch phones,I am getting this in launch screen storyboard which i filled with one imageview.Can anybody guide me in right direction in achieving this ?
Size classes are based on ratio of width and height, not size. In portrait, iPhone 6, iPhone 5, and iPhone 4s all use the compact horizontal and regular vertical size classes. So They could look different on each.
When you design UI Interface for 3.5 inch iPhone in Storyboard, you should set the Size to iPhone 3.5-inch in Attributes Inspector. By doing this, we ensure what we will see in simulator is same as in Storyboard.
Sometimes, You may need to make size class specifically for portrait 3.5 inch (iPhone 4S).Then you need to set auto layout according to the size of screen, like:
if (UIScreen.mainScreen().bounds.size.height == 480) {
//Set your auto layout here
}
I'm building a UICollectionView where each cell has size of 159x159.
When the app runs on ios8 it gives (whatever the simulator i choose : iPhone 4S, 5, 5S, 6, 6 Plus) :
But it has not the same size on iOS7 :
WTF ? Note that even my SearchBar has not the same width on both simulators.
The reason for this is that iOS8 has layout margins whilst iOS7 does not. You have made your constraints of the views to the margins.
The way I would facilitate it is if you want it to look like the iOS8 version in both, then don't constrain the views to the margins, but to the edges themselves, and have a constant space between the views and the edges. If you are using storyboards for the auto layout, then you will notice you can tick either on or off if to constrain to margins or not.
I am designing an iOS 7+ app on Xcode 6 for the iPhone 5s, iPhone 6, and iPhone 6+. I want to create a single design for all of these devices, so I am using Auto Layout. I would like the spacing between UI elements to be the same on all devices, but I am having trouble accomplishing this. Here's a screenshot of one of my UIButtons on the iPhone 6 Simulator at 100% scale:
(The white boxes are spacer views, but don't worry about them.)
As you can see, the horizontal spacing from the left edge of the UIButton to the left edge of the UIViewController is 37px. On the iPhone 5s, this spacing is 32px. I would like the spacing to be 32px on all devices. On Auto Layout, I set my horizontal spacing constraint to a constant of 32. Even with this set, it seems to be scaling the spacing as well.
How can I prevent the horizontal spacing from scaling?
I think your app is not iPhone 6 ready. If your app is iPhone 6 compatible, spacing will be 32px across all devices. Otherwise, iOS draws screen 320px in width and scale it to fit actual screen width. That's why you're getting 37px in iPhone 6.
To make app iPhone 6 compatible, create launch screen file (new file > iOS > User Interface) and assign it as the launch screen file in your project settings. Then app will launch in devices native screen resolution.
With the new iPhone 6 Plus, in landscape the phone can show more content than the normal iPhone 6 or its predecessors. This makes sense, as in landscape the phone identifies as having a "regular width" for its size class.
However, in portrait its' still compact width, regular height for the size class, regardless of which iPhone. How is Apple then showing more on the iPhone 6 Plus in portrait when there's no size class identifying it?
Are they hard-coding it based on the device's width? Doesn't that go against the whole philosophy of size classes?
They are using auto layout to force their labels to adopt the width of the screen. There's a good description of how to achieve this in this SO answer.
Apple have also used Adaptive layout to implement the landscape view on Mail for the 6+.
I've been working on a specific app for a while now and everything was good. But upon all this news of the iPhone 6 and the new Xcode, everything has just become confusing. Using Auto layout and designing for the iPhone have just become the most complicated thing to do. Every time I add constraints my images just triple in size. When all I want is to resize them to fit rationally across all the iPhone platforms(In portrait mode). For example I would like for certain images to grow as I work From the iPhone 5 to the 6+. Does any one know how to do this?
What do you mean triple in size?
Easiest way to have an image view scale is do the following:
Add it as a subview to the view of your view controller
Pin it at the top, left and right, leaving height unconstrained
Add an aspect ratio constraint, so that it can automatically calculate its height based on the width it gets