So I've spent a lot of time creating an app and I noticed that I've been building it on a compact width and any height base values. Can I keep my changes and set it to any width and any height? Because now when I change it to that all my changes have disappeared. (my changes are EVERYTHING, I started making the app using compact width and any height)
Or will I need to switch to any width any height and restart my entire app? :(
please help
A size class doesn’t necessarily map to one device in one orientation. For example, an iPad can have a view with an iPhone style layout (i.e. compact) when presented in a smaller space and an iPad style layout (i.e. regular) when the space is larger.
This means you can have a unified storyboard when building a universal application.
If you think there's anything wrong with it you can disable some constraints. These constraints won't apply to your current layout but still work for others. You can add some new constraints and the new constraints will work at the current size class.
Related
I've had several attempts to try and convert my iPad app to make it universal.
I'm only supporting landscape on iPhone / iPad.
My existing iPad setup uses a storyboard without autolayout, which works fine.
My app had lots of images and about 10 screen each with a minimum of 6 views on each, however some have 20 or 30.
I decided a couple of weeks ago that it would a far greater nightmare with all the images, so I've created paint code classes for all my images.
When I first turned on sizing classes / autolayout, Xcode asked if it should enable suggested layouts, this seemed to make sense. However it's made a real mess of the any / any layout.
Without adjusting the sizing classes setting any / any, I tried to install constraints for differing sizing classes. I want to make views bigger to fill the space, so I installed constraints with equal width (with aspect ratio) to subview with a multiplier so I would get proportional sized views. However this means I have about three sets of constraints per view. Which is a nightmare on my simple screen.
I then thought it might be better in my case to leave my iPad storyboard and have an iPhone storyboard. But my iPhone 6+ layout won't look very good. Turning on sizing classes made little sense with multiple storyboards.
I'm now thinking I could click the sizing class to regular / regular and compact / compact and have different views for each?
However any / any, which I can't get any sort of layout to look good, will still need views?
I'm also wondering if should let Xcode setup autolayout when I first enable it? As I say any / any looks bad.
I was thinking I could just plop my views in a vague position with any / any, apply suggested constraints, then click / flip to compact / compact and regular / regular and move things around.
I guess I'd also need to do that for compact / regular for 6+ too.
I'm just not sure what steps to take, I can't even think of workable plan b.
I've watched a million videos and feel I understand but I can't put it into practice.
HELP
My Suggest steps would be:
When we use autolayout and size classes, We always take start from wAny hAny
Take your simple Screen First Let say your login screen on ipad LandScape without autolayout will look like this:
Now you enable autolayout and size classes. Change Scene size to inferred (600, 600).
Now your view look terrible:
First Adjust it by just moving the views to center and correct places like this.
Now we are all set for applying autolayout constraints.
First give constraints to parentview(grey view). Unless parent view has correct constraints, childs view cannot be given correct constraints. So always make sure parent view have correct constraints.
Now we select the grey view and apply constriants like this:
Center vertically and horizontally in container.
Add width and Height Constraints. You got options. Give fixed width and height and modify it for different classes. like this:
Or you can add proportional constraints for width or height.(Better)
Now start with childs. Give them leading, trailing, top and height.
Height of label is 50 for wR hAny and 40 for wR hCompact
Final Results:
IPAD LANDSCAPE:
IPHONE LANDSCAPE:
Autolayout and size class are great and easy when someone get used to it.
HOPE IT HELP.
You have 2 options
1) Create separate layout for iPhone and iPad. In this options you might have to compromise targeted customization for iPhone6+. This option will consume less time, and if you have a time constraint or you think that you are not convenient working with autolayouts then go with this option.
2) Using any/any size class and add constraints to make you interface alright for iPad. After that only modify/add those constraints for iPhone specific size classes which needs to be adjusted. Once you have layout set with any/any for one of the device either iPhone or iPad, you will be surprised to know how much less constraints you will have to modify for specific size classes. This option requires good understanding of autolayouts or even if you are not convenient working with autolayout but willing to try and have no problem with time constraint then you should definitely go with this option.
I have a simple layout with multiple views and constraints to position and size them as I need. When I deploy the app to a simulator or device, the X, Y and Widths of all the views have the proper sizes. The Height on the other hand is always 0. All the views have proportional heights according to the super view.
Now, if I flip the orientation to Landscape and then back to portrait, everything shows up properly (the heights are no longer 0).
I've used the same logic with proportional heights previously, and I started seeing this problem with newly created view controllers after updating to Xcode 7.
EDIT You can get the .xib from: http://1drv.ms/1M81EUQ
you have to Set different view update method call regarding the orientation changed if you use auto mask resizing or used autolayout to fix this .
Your .xib was configured with Size Classes enabled, but your views and constraints were all configured to only be applied for Compact width, Regular height.
I went through and changed the views and constraints to apply to Any width, Any height, and this resolved the issue with landscape layouts.
Download the modified .xib file here
I recommend using Xcode 7's Preview Assistant View when working with Autolayout, as it will let you see multiple devices, in multiple orientations at the same time. This really helped in this case with showing that the layout was fine in portrait, but not in landscape.
This is what I saw in your .xib as you provided
And with the changes in my .xib
How could this have happened? One way is that you may have accidentally set the storyboard editor to a specific size class. If you see a blue border at the bottom of the editor, anything you add will be configured to be only installed for that specific size class. You can click on the size class shown to change it out to w Any h Any to return to the default mode.
I have a label in a custom cell and it currently has a width constraint of 150. When the phone goes into landscape orientation, I would like to increase the width constraint to 300. Then of course change it back to 150 when phone goes back to portrait. How could I accomplish this?
You can combine Size Classes to achieve this. You can set up 300 on AnyWidth CompactHeight(landscape mode for iPhone) and set up 150 on CompactWidth RegularHeight(portrait mode for iPhone).
Enable Size Classes in the Interface Builder Document. Then, you will need to configure based on on different size classes. More information, you can find it online: Adaptive Layout from Ray Tutorial
Another approach will be: changing the constraint's constant value based on different mode of the screen. You will need to reference the constraint as IBOutlet and then change it programatically. But, we don't suggest to do so because Apple is tended to have different size of device and it's better to work on layout by combining Auto Layout and Size Classes
I am building a single view application with 12 different view controllers. I built all of the view controllers in "any width" and "any height" and added all constraints for each page and also first ran the simulator with an iPhone 6. However when I switch to other devices to run in the simulator, smaller and larger, the images I have on the view controllers become very distorted and the font sizes become disproportioned with the rest of the screen, despite adding in all necessary constraints. Do I have to redesign each view controller to fit each size (for example regular width and regular height for iPad or compact width and regular height for iPhones in portrait, etc.)? Or is there another way to maybe get all of the images/ font sizes into proportion with each screen size, again small and large? Thanks
Constraints are fine in this case, you shouldn't have to redesign every view for each device size. For your images, try changing them from size to fit to aspect fit or aspect fill in the right-hand pane in Storyboard. This will keep their aspect ratios intact. I suggest starting out with using reset to suggested constraints on all views that you can before you fully get the hang of constraints. This will generally work most of the time.
I am using Xcode 6.1 and in one of the views I have, contains many labels. However, these labels look different in each different devices. Although I have add constraints to all the labels, but still facing the same issue.
How can I get the same view layout across all devices?
How can I make the width and height for each label is flexible, depends on the screen size?
Do I need to design different xib for each device?
The following images showing the result am getting, with auto resize enabled, and constants been added.
on iPhone 6
on iPhone 5
on iPhone iOS 7.1
We have provided with a simple solution . Using Aspect ratio constraint we can get a relative look in all device screens.
I had the same issue and I found this >>
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
So when designing for lowest to highest screen resolution we can't set a specific width and height for all controls as it may look weird. So using this constraint we can have a relative look for all screens.
If you don't want to use constraints or you want to keep the same width & height , you can add scrollview to hold all controls. For that you can set a resizing frame for scrollview with fixed content size .
To solve this...
1) Go to xib file and uncheck the Auto layout
2) Then set the autosizing manually in the following manner for each and every subview.
Use self.view.bounds.size.width to get the width of screen, then use relative value to initialize all labels.
One soultion is that you can Design a story board for each screen size like one for iphone 5, one for iphone 6 and one for iphone 6+ and in your AppDelegate method "didFinishLaunchingWithOptions" you can get the screen size and popup corresponding storyboard
in this wasy you can set different constraints according to different screen size