I would like to design my iPhone App so that, e.g., my buttons are centered, or my inputs are set to the full viewport width and so on. Is this possible using only the storyboard, or do I have to create every view element in the controller and then alter it on orientation change?
Yes this is possible with "AutoLayout",
I would recommend this tutorial for a better understanding:
http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
In Xcode 5, Auto-layout is enabled by default. You also may want to try adding the recommended constraints from the Editor menu.
Related
How can i make a view like this. I am done with first portrait mode and confuse to to achieve the landscape mode.? can anybody suggest me how to make the view in landscape mode. I have done portrait mode in AnyHeight AnyWidth format.
Although the question might be a little broad, I'll try to mention a generic answer.
Assuming that your are already familiar with Auto Layout and Size Classes, in Xcode 8, Interface Builder you can change the current view of what are you working on:
By tapping the "View as:" button, you will be able to see the desired device orientation to setup the desired layout via device configuration bar:
For example, Consider the following View:
As yo can see, both of the views have the desired constraints to be displayed in portrait mode, for now, you should add add new constraints for the landscape mode. Make sure to deinstall the constraints for portrait mode:
As you can see, some of the constraints appears faded, which means that they are uninstalled on this size class. You can determine installing the constraint by selecting it and from the attribute inspector, check the desired size class(es):
For more details about how you can achieve this, I would suggest to watch Making Apps Adaptive, Part 1 Session.
Hope this helped.
I have been creating an application for iPhone and iPad. I am using Auto Layout (wAny and hAny). Now I want a separate design for iPhone 4s alone. How can I use separate designs for this device. I already completed most of the designs with this wAny and hAny. How can I change this.
Edit:
I want to change only few view controller not all the designs.
I suggest not to go with different storyboards. You can add 2 views inside that viewcontroller's(for which the design is different) view and toggle it programmatically depending on the device. Regarding autolayout, set wAny and hAny and add constraints accordingly.
VC.view
-iPhone 4 View
-Other device's view
This can be done in storyboard only.
So programmatically when loading the vc, check the device and show the specific view hiding the other view. In this case in future, even if the design is normalized, you can easily use the same view with change in one line of code.
This is necessary if the design is totally different. Or if it's just few sub views which are different, I think you should write some code to hide and unhide the subviews acc to the device.
I am a novice in iOS, please correct me if I am wrong anywhere.
Better to go with design it as separate controls if you have design changes and load it conditionally for 3.5 inch screens . If its a simple changes (easily managed through codes) then go with codes itself.
I've been using size classes to hide and show certain views by adjusting / animating their constraints to move them in and out of view.
This is sufficient for a lot of cases but I want to see if a different approach is possible.
I want to know if it's possible to completely remove a component from the screen based on size class.
For example,
While in landscape mode I have 4 buttons on the screen.
When switching to portrait mode I remove 2 of the buttons.
Ideally I would like to achieve this using just storyboards.
Thanks,
You can "remove" a control on specific size classes using the installed checkbox in the Attribute inspector :
I have already developed an IOS app in Objective C, Xcode 6 in which I have disabled the auto layouts and size classes.
Is it now possible to use auto layout after having disabled it earlier?
If yes, how can I implement it? When I enable the auto layouts and size classes and I implement the constraint on the label, the background colour of the label changes to white. When I do this for other object types, they become invisible.
To answer your first question, yes: it is indeed possible to use Auto Layout in an app after having disabled it. Each Xcode project template just gives you an initial starting point – nothing is set in stone.
For the second question, the best way of implementing Auto Layout in an app is to just take it one view at a time. You don't need to go all-or-nothing with Auto Layout; it's possible to just use it in certain cases but use frame based layout in others. Start on smaller, easier views and go from there.
The last issue around background colors is a little trickier without having screenshots or code samples. I have had views disappear on me after implementing Auto Layout and the issue always boiled down to bad constraints. The best solution I can give there is to just do the usual view-debugging work (as in, printing frames and manually setting bright colors to see where views actually are) and figure out what is going wrong.
Having the background color change to white is interesting, though... Auto Layout should not be affecting that at all. It sounds like the background color got changed somehow while the constraints were being created.
I have an app which has a different UI for portrait and landscape. I've heard wonderful things about Auto Layout but in all my readings it seems to handle simple cases, where UI widgets resize and reposition simply. In my UI UI widgets move. Is this a case where I should try and get auto layout to work or should I just make 2 xibs and be done with it?
You can see in the portrait version that the green element is below the magenta one, but it is above it and next to the orange one in the landscape orientation.
Sorry, one auto layout setting will not allow you to rearrange views like that. You could still use auto-layout for positioning and spacing, but you'll need two sets of settings.
You could still use one xib file and change the auto layout settings at run time, but most likely multiple xibs makes more sense because you'll be able to see and edit your UI WYSIWYG style.
Update
Also, take a look at iOS 9's new UIStackView.