I have developed an app with Xcode 7 and I placed all my views for all iPhones in portrait. Now using Xcode 8 I want update the constraints for supporting iPads in portrait. How I am supposed to to that? Copy/Paste views and start from scratch? I can't see any other solution.
PS. Note that views for iPhone 7 Plus to iPhone 4S appears fine.
No need of copying the views. The Xcode SizeClasses aids you in designing the app for various devices.
I suppose you may have used the Any Width Any Height (wAny hAny) or the Compact Width Regular Height (wC hR) to design the portrait orientation screens. Now use the Regular Width Regular Height (wR hR) size class to design the iPad screens. Size classes will automatically switch sensing the device rather than programatically selecting one among the two storyBoards designed for iPhones and iPads.
Select the wR-hR size class. Select your view in the Document Outlinein the storyBoard. In the Attribute Inspector install the view for the current size class (wR hR). the view will appear in the storyboard scene. Set the suitable constraints and you are good to go.
PS: Of course you must set the constraints again unless you have designed the iPhone screens in wAny hAny size class. If so that works in iPads too and you needn't work on any other size class.
Related
I have the following constraints attached to an input field. However when I switch from iPhone 6 to iPhone to trailing constraint of 16 isn't applied.
Why is this happening. I don't have an width constraint so why would it behave this way - and how do i fix it.
These are just warnings, that you can ignore. Yellow marked warning, is a kind of suggestion for update, it won't make any effect/changes in your interface design and their frames until you apply suggestion.
Simple advice: Do not change Interface design (device) size in storyboard. Choose one fixed device size according to your project target (I suggest iPhone 4S or iPhone 5) and setup your all interface design for your project with respect to fixed device size.
Note: Warning will be not visible to you, until you change device (frame size) in your storyboard layout
To check, interface preview for different size of devices (including iPads), there is an option for preview of all size of device. Without changing your storyboard interface view (view controller) size, you can see preview of all layouts from preview screen.
Here is snapshot, that I designed for device iPhone 4S but I can see preview for latest update of iPhone X also, without changing storyboard layout.
I'm new to ios(android dev). I'm using storyboard, and autolayout.
To optimize application for tablet, i used sizes in storyboard regular width regular height.
I want to align ui items on ipad different than on iphone mode. For example, i have a table of textfields that occupy full width on iphone. On ipad i want to place two or three textfields in one cell. How can i make different ui implemetation for ipad, so the logic shoudl stay the same.
I watched https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html#//apple_ref/doc/uid/TP40006556-CH54-SW1
But there is no answer there.
Jenya Kirmiza,
Size Class is what you want :) Size classes were introduced with iOS8 in order to avoid the multiple storyboards for universal applications and yet provide an easy way for the developer to design differrent UI for differrent Devices :)
I expect you to know SizeClasses, In case you are not aware each device in its various orientation falls to one of the sizeClass defined by Apple.
One thing important to note here is that iPad in its both the orientation falls to Regular x Regular size class
Where as all iPhones other than iphone 6S and iphone 6s + will fall to
Copact Width x Regular Height - Portrait mode
Compact Width X Compact Height - Landscape Mode
Iphone 6s and 6s + falls to
Copact Width x Regular Height - Portrait mode
Regular Width X Compact Height - Landscape Mode
Now that you are equipted with the information of all size classes lets nail this issue down. When you open the story board at the center of the screen there is option to decide the size class :)
So go ahead open up your story board when you see it by default will be in wAny wAny mode What it means is whatever the components you add and add the constraint to it will be applicable to all the sizeclasses irrespectively.
Hence you see the textField added at the center of the screen appears center in all the devices may it be iPhone ot iPad.
For explaining Ill add two text fields named Firstname and LastName :)
Lets start adding textFields and constraints to them in storyboard keeping wAny wAny mode.
Now I have added two textFields one below the other covering the whole width of the screen in any any mode :) This will work fine for me in all iPhone devices :)
But I want to allign them side by side in iPad. Now we know that iPad belongs to Regular x Regular sizee class in both the orientation :)
So Simply change the size class in storyBoard
Now when you see you will see two textfields added one below the other already :)
Now select those textfields we want to align them differently isnt it :) So will have to remove the constraints already added to them :)
Now move them place next to each other add constraints properly :)
Thats it now run on iPhone and iPad :) You will textFields one below each other in iPhone and one next to other in iPad :)
iPhone Output :
iPad output :
Hope this helps :)
I have to design an app for all iPhone size portrait mode only. I am using storyboard and setting constraints using storyboard itself. What makes me confuse is Size Classes. Since my requirement is iPhone portrait only, I am using Size Class compact Width|regular Height. My question is can I disable the Size Classes cause working only for iPhone portrait mode. If yes, then can I design with Size Classes disabled for all iPhone size. What is the right approach?
Intuitively, prior to size classes, storyboard UI was designed by doing a separate interface for each iPhone size. Since the advent of a broad range of device sizes, size classes have been incorporated. Considering that your app may have to run on older devices, there is still a difference in size between iPhones in portrait mode. Because of this, you would likely have to make a separate interface for each orientation, which I have not tried. I believe the correct approach would be to simply design for the size class that you selected.
If you are only making your application for iPhone portrait not necessary to use the size classes. You just have to set proper contract which are in the size indicator.
It's my opinion for it.
If you are developing for iPad and iPhone size class is the best option.
Size classes deal with the problem of multiple orientations(portrait and landscape) and different devices(iPhone and iPad). You cannot differentiate between two different screen sizes for iPhone using a size class. Similarly you cannot differentiate between iPad mini(portrait) and iPad Air(portrait) on behalf of size classes.
All iPhones in portrait has the same size class behavior i.e Compact(width) | Regular(height), be it 3.5", 4.0", 4.7" or 5.5". Similarly all iPhones in landscape has Regular(width) | Compact(height) size class. Size classes aren't the solution to the problem you are facing.
In order to handle multiple screen sizes for iPhone in portrait, the best bet would be to make use of autolayouts. Pin your views with the boundaries so that they will get stretched or contracted on different screens. Similarly bind your labels with the boundaries of their superview so that they will grow too. Also you can make use of aspect-ratio constraint that will allow to grow your view and images relative to the aspect-ratio of the element rather than increasing them horizontally to end up with an elongated look.
If you are new to autolayouts I will highly recommend watching the following sessions from WWDC2012:
Introduction to Auto Layouts
Auto Layouts by Example
Best Practices for Mastering Auto Layouts
So I've built this app and the layout is so that it requires me to use two size classes:
1) wCompact hAny
2) wCompact hRegular
All the alignments and all that is great and this should be giving a smooth, consistent display across all devices. However, it seems that the 2nd size class is overriding the 1st one in all situations. I only want number 2 to fire up on 6+, but it's doing so on 6 and 5s as well.
How can I fix this? It's really holding me up on here.
Thanks!
The First size classes you are using is for iPhone 4,iPhone5s and iPhone 6 for Portrait and landscape .
The Second size classes you are using is for all iPhone devices in portrait mode only.which means obviously they are overriding each other.
Use only second layout for all iPhone devices in portrait mode. and if you want to use size classes for landscape mode wAny hCompact.
For more details aboout size classes follow this link.
Size classes
I am trying out the new Xcode6. When I create a new project for an iPhone and I open up the storyboard, the default UIViewController is wider than the iPhone width.
Why is that so?
That's due to a new feature in Interface Builder, that enables designing for multiple device sizes and orientations in a single Storyboard. From the docs:
Size classes for iOS 8 make dealing with different screen sizes and
orientations more flexible. You can create a single interface that
works on both iPad and iPhone, automatically adjusting to orientation
change as well. Use size classes to design a single, universal
storyboard, with small customizations, which adjusts to the strengths
of each form factor. There is no longer any need to create an
device-specific storyboard—instead, you target the appropriate size
classes and tune your interface for the best experience on each
device. iOS Simulator fully supports size classes as well.
When working with size classes, ViewControllers are represented with square views by default, in order to make clear that you aren't laying out the views in a specific orientation or interface size.
You can disable Size Classes on a per storyboard basis. Just uncheck the Use Size Classes option:
For more detail on Size Classes, refer to the Apple Docs