Support for ipad size in Swift 4 - ios

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".

Related

Device Layout Does Not match Simulator or Storyboard

I've been away from Xcode for a while, so I may have missed changes in the latest couple of releases. The layout of views looks identical in the Storyboard, and on the simulators (iPhone6 and iPhone7), but different on my iPhone 6. I have no warnings or errors in the Storyboard, and I am using Xcode 8. The device acts as if it had a shorter screen than the simulator -- things that are spread appropriately on the storyboard or simulator, are squeezed together vertically on my phone. What is the reason for this difference?
Have you assigned launch images with the correct dimensions for the different form factors? An easy way to verify this is to add a print statement in a view controller to see what the bounds are for the screen. Verify that these values match what you expect for the device.
The following from Apple documents this:
Because device screen sizes vary, launch screen sizes vary too. To
accommodate this, you can provide a launch screen as an Xcode
storyboard or as a set of static images for the devices your app
supports. Using an Xcode storyboard is the recommended approach, as
storyboards are flexible and adaptable.
While not an official Apple site, this link also references this as a potential issue:
The launch XIB or storyboard is required to support iPhone 6 sized
apps.
Another possibility is that you have the screen zoomed in on the device. To change this, go to Settings > Display & Brightness and select Display Zoom at the bottom. Ensure that you have Standard selected. If you are zoomed in, then the device will scale down (A 6 behaves like an SE, a Plus behaves like a 6/7).

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.

Autolayout(xcode 6,swift)

In I phone 5s simulator its working fine! I have one label,one image view and one button.As you can click on the link and see the picture now so i tell you that I used my image view as a background and the label is in the middle and the button is in the lower middle so i want that to look same in all the devices. i don't know anything about constraints.I am using Xcode 6
https://drive.google.com/file/d/0B2z_d4wEKPEFLV9RNFVlR3A5SFppa0tJT2tiQkQwVVVVTDVz/view?usp=sharing
I suggest you to take a look at this youtube tutorial. I learned how to make the constrains by watching it. The tutorial teaches how to make the similar layout as you required.
Link: https://www.youtube.com/watch?v=RpMzEmF-xZM
Hope this is helpful~
Autolayout is the tool used to make UI look similar across all devices, you should try to learn it if you want to continue to develop IOS apps. The concepts are pretty basic and are used throughout other languages.
This tutorial is useful if you want to create the auto layout using storyboards.
This tutorial is useful if you are making the view programmatically. I tend to use code for auto layout but it is just a preference, storyboards is fairly simple so I would suggest that. If you are going to do it in code a is to forget setting the autoresizing mask into constraints to false. You have to set this property on all the views you want to use auto layout for.
view2.setTranslatesAutoresizingMaskIntoConstraints(false)
Background ImageView
Select Image ->Pin->Uncheck Constraints to margin-> select top,bottom,left,right.
Button
Select Button-> Pin->Uncheck Constraints to margin->select bottom,left,right,Height.
label
Select label->Align->Center horizontally and Center Vertically in Container.
Pin->Width,Height.
If it is working for iPhone 5 but not another layout then this is probably happening.
There are demensions in the centre of the lower tab bar of story boards
There are screen size settings in the story board and regular*regular is the only one that is universal to all orientations and sizes of the ios device. if you set constraints while viewing in regular by compact (landscape for 5.5 inch iPhone) then those constraints will only be apply to 5.5 inch iPhones in landscape and if you tried running on a smaller iPod it would be as if you never set the constraints. the constraints for the 5.5 inch iPhone would not apply to the small iPod
if constraints were made in compact by compact and you were viewing the story board in say regular by compact then you would get an error saying that things are misplace and will not appear in the same at runtime. view the storyboard in the same dimensions that you set the constraints and you should not have an issue.
There is an option to simulate the device you want to run on specifically in storyboard and it can be say only 5.5 inch iPhones or something, whatever device.
go to paul hegarty developing iOS apps with swift on iTunes you if you want to learn more. He is a good source.

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:

How to use adaptive layer for universal app but different button sizes on ipad in ios8?

I'm developing iOS 8 universal app, I'm using adaptive layer to develop app, all going well.
But, I struck at iPad design, because I used equal width and height for all devices using constraints, its looking good for iPhone devices, but iPad also is showing as like iPhone design, so I need to increase button sizes, so can I use a separate constrains for iPhone and iPad buttons on single storyboard app in iOS 8 with Swift language.
One more doubt is, how to handle dynamic buttons on same storyboard application with auto layouts and constrains
Thanks in Advance.
You can select Regular width|Any Height size class and set the size and constraints for the button specific to iPad. According to Apple docs :
Views, constraints, and fonts are added from the size classes in the same way they would be chosen for display on a screen. Items from Any|Any are used unless those items are changed or uninstalled in more specific size classes. In that case, the most specific item is used. For example, in the iPhone nib, modified items in the Compact|Regular size class take precedence over items in Compact|Any. And modified items in Compact|Any take precedence over items in Any|Any.
Regular width|Any Height size class is taken in run time for iPad and Any|Any is taken for iPhone.

Resources