Universal iPhone Auto-Layout - ios

I decided to make an iPhone-only application but since there are so many different sizes of an iPhone screen I have no choice but use Auto-Layouts. There is a grid which allows you to chose width and height of the layout so I decided to choose the "wCompact hRegular" one because it says "Any iPhone in Portrait" but every time that I run my application on iPhone 6 it uses the "wCompact hAny" layout which does not work right. So my questions are:
Is there any way to use ONLY wCompact hRegular layout?
Is there a way to not use Size Classes and just stretch 16:9 iPhone 5
version?
And if there is not, what is the best solution for my problem?
Thank you in advance!

Better you disable "Size Classes" and use "Auto Layout" instead. To do that 1. Select your storyboard file from your project navigator
2. In the file inspector under interface Builder Document check "Use Auto Layout".

Related

Support for ipad size in Swift 4

I have successfully completed iPhone development using Auto Layout.
Thanks to Auto Layout, UI is displayed normally on all iPhones.
However, if I run it on the iPad, the UI will not break, but the screen will be small.
I have no idea what to do to support iPad size in storyboard or build settings.
If I want my app to respond to iPad size, what method should I use specifically?
I am using Xcode 10 and Swift 4.
Select your project in Xcode, then use the General tab. It's under the sections on Identity and Signing.
1) Select constraint that you need to update for iPad.
2) Click on + sign to the left of "Constant" value
3) Select Width and Height - Regular which conforms to iPad in portrait and landscape orientation and set your values
4) Now when your select iPad second value will be applied to your layout.
Also you can vary font for different devices:
Every settings that has + sign on the left can be vary for different screen sizes and orientations. You can read great tutorial about variations on
Ray Wenderlich web site
You want to use "Vary for Traits" when editing the storyboard. You can then adjust the layout for the different sizes of iPad.
As stated in the comments above, check your deployment info also to ensure it's set to "Universal".

How do I adjust my layout?

I am moving from Android to IOS, and am following this tutorial. The problem is that my layout is not adaptive, as should be the default. The tutorial shows the layout to be like so:
However, my layout is not adaptive (universal) for both iPad and iPhone, and the UI is only that of an iPhone:
I searched a lot on why my layout is not universal (it should be by default), and most of the results said I need to enable Size Classes.
For me, however, the option to enable Size Classes isn't even there, I have the options:
Use Auto Layout
Use trait variations
Use as launch screen
How do I make my storyboard adaptive and enable Size Classes?
Thanks,
Ruchir
I think your UI is adaptive, it's just that in Xcode 8 the storyboard shows the UI in whatever device you have selected. If you look at the bottom of your screen in storyboard view it's says iPhone 6s, click that and you can select to view as a different device (iPad included). So even though it doesn't look like it, it should be adaptive.
As a side note size classes are only for if you want the UI to be different between devices, not adaptive.

Supporting all iphone sizes

I'm trying to create a iOS app, but I'm stuck on the layout.
I created the home view, but now I see that it's not shown in the right way in the 4S simulator.
I tried with size classes, but it looks like 4S and 6, for example, are in the same size class, and so I can't set a different dimension for views.
My goal is to support all devices, also iPads. Can someone please tell me how to do it?
Size classes mostly used for separation between ipad, apple watch and landscape modes.In potrait mode iphone 4 to iphone 6 all phone device sizes are in same class(regular height and compact width).Autolayout has many different constraints to help you to fit interfaces in same class.You should consider horizontaly/verticaly align, equal width and aspect ratio constraints.They are so flexible for smaller size changes and help you to design adaptive layout.
You should use "Reset to Suggested Constraints" for all views in your View controller. You can also check the simulated metrics for all devices without compiling the the code.
For 4s and 6 by default the size is Inferred. You should try resetting the constraints to check this for iPad as well.
I am just sharing an idea
Option1:
I think You can try adaptive Layouts and in file inspector->simulated Metrics->size-> Inferred. It works in all devices it supports both landscape and Portrait.
Option2: Go for Visual layouts they are easy to understand and they work perfect in all modes of Portrait.
I am think that you use code Instead design in main.storyboard !
for ex: create button with code
(and use Ratio in your code)
by this way i create small app for iPhone & iPad
!

Why are my storyboard views not iPhone-shaped?

I am building an iPhone app, and the storyboard looks like this:
Notice that the views within the storyboard are awkwardly square. I wasn't sure what caused this so I just went with it.
I set my app as iPhone-only and portrait-only.
When I build the app on my phone though, parts of the view are off the screen, because my phone isn't shaped like the interfaces that I am building.
Anyone know how to fix this?
In Xcode 6 Viewcontroller sized to 600*600 size, its for Auto layout and size classes. You can disable this feature by unchecking autolayout and size classes in the File inspector of storyboard (refer image). If you disable autolayout you can see your storyboard viewcontrollers sized to iphone.
It is Universal Storyboard.
Apple wants developer to create apps with Adaptive Layout
The introduction of Adaptive Layout in iOS 8 is a huge paradigm shift for iOS app designers. When designing your app, you can now create a single layout, which works on all current iOS 8 devices – without crufty platform-specific code.
This tutorial serves as your introduction to Adaptive Layout. You’ll learn about universal storyboards, size classes, layout and font customizations and the ultra-useful Preview Assistant Editor.
--Edit--
If you want to fix the size of storyboard you can adjust width and height.

UIWebView content not scaling between different iPhone sizes

So I am working on an iOS app that uses the UIWebView to serve HTML content. Why UIWebView and not WKWebView? well I want this app to work on iOS7 and above. I have just updated my Xcode to Xcode 6.1 and I cannot get my webView to scale to fit the available screen space when changing from the 4 inch screen size to 4.7 and above.
What I am after is to have my app look consistent on all iPhone screen sizes of 4 inch and above as all my HTML5 code that is displayed on the web view is.
In my Attributes inspector I have set the size to iPhone 4-inch and you can see what the app looks like in simulators for iPhones of size 4-inch and 4.7-inch respectively in the link below,
http://imgur.com/gallery/tz7LG/new
How do I get this to scale up appropriately on iPhone screens of different sizes?
fyi, I have set the Scale page to Fit to true for my webView. I am building this app using Swift.
To solve such issue,
1) Uncheck "Use Auto layout" and also disable size classes.
2) Open the size inspector to use Autoresizing as directed in the image below on the desired element (in your case its UIWebView).
Try selecting the bounds as per your requirements.
This will surely solve your problem.
Do check that you haven't coded the dimensions in the .m file.
The answer by Piyush Mathur is simple and seems usable in the given case.
But if the requirements are complex then you need to "Use Auto Layout".
Also make sure that you have set all the needed constraints of the Web-View.
The Introduction to Auto-Layout gives an idea to set constraints to a component which will also give an idea to stretch component (Web-view in your case) based on the device screen size.
You could use Xcode's auto layout tool, which will automatically resize the UIWebView according to the device.
I think the best practice is to untick "constraint to margin" when you add the constraints.
Here are three steps: 1. clear all constraints; 2. add the constraints back in and untick "constrain to margin"; 3. set all four constraints to 0.
Or if you are familiar with the Xcode, this can be done in one step.
What helped me is a creation of 4 constraints:

Resources