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

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.

Related

different ui items alignment for tablet

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 :)

Swift layout for different orientations

How can I make different layouts for different orientations on ios?
I try to make an layout in landscape to show 6 picture's in 2 rows.
But in portrait I only will show 4 pictures in 2 rows.
I already have 2 different storyboard for iPad and iPhone.
Can I do this over constrains?
Can I do this with different storyboards like in android?pain
iOS has something called Size Classes. You can use a size class to target a specific device and/or orientation. You can choose the appropriate size class at the bottom of interface builder (wAny hAny) and layout your view accordingly.
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html
Adding on to #Nitesh's answer: Correct me if I am wrong, I am not very well versed in iOS development as well. I read that it is almost always recommended to use Size Classes while only using one storyboard for all targeted devices. It makes handling issues like screen sizes and orientation much more managable.
In your case, may I suggest using UICollectionView to achieve that effect? It rearranges your tiles based on how much width you have and it supports orientation quite well.

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.

Supporting multiple iPhone resolutions with a single storyboard

We all are going to update our apps to iphone 6 and iphone 6 plus. That means we need to support 4 sizes.
1.) 3.5
2.) 4
3.) 4.7
4.) 5.5
Can we support all these screen sizes with single xib or storyboard ? also please share your views on how we can update our existing apps for iphone 6 and iphone 6 plus.
Yes. See Apple's iOS8 documentation specifically, size classes:
iOS 8 makes dealing with screen size and orientation much more versatile. It is easier than ever to create a single interface for your app that works well on both iPad and iPhone, adjusting to orientation changes and different screen sizes as needed. Design apps with a common interface and then customize them for different size classes. Adapt your user interface to the strengths of each form factor. You no longer need to create a specific iPad storyboard; instead target the appropriate size classes and tune your interface for the best experience.
There are two types of size classes in iOS 8: regular and compact. A regular size class denotes either a large amount of screen space, such as on an iPad, or a commonly adopted paradigm that provides the illusion of a large amount of screen space, such as scrolling on an iPhone. Every device is defined by a size class, both vertically and horizontally.
There is also a very good tutorial video on the WWDC site.
In order to stop your iPhone 6/6+ app being scaled, add a launch image of the correct size or better, use a launch storyboard.
From there you should use AutoLayout and avoid hard coding to screen sizes. In the long run it'll be a lot less effort and less error prone.
In existing projects you can use autoresizing or auto layout of xib files.. that support all 4 devices.
I have implement my projects using autoresizing to support all devices.

How/whether to make a universal storyboard in Xcode

When creating a storyboard file in Xcode, you must select if it is for iPhone or iPad. This implies one should always put iPhone and iPad UIs into separate storyboards. Is this true?
My app has multiple storyboards. While the Main.storyboard files largely differ between iPhone and iPad, other storyboards are nearly identical. The only difference might be segue being a push on iPhone vs popover on iPad, which can be handled programmatically. It seems awfully silly and redundant to make two storyboards.
So if making one "universal" storyboard, should iPhone or iPad be selected in Xcode? Does it matter?
As of Xcode 6, we can create a single unified storyboard for all the devices.
For more info - Documentation
iOS 8 makes dealing with screen size and orientation much more
versatile. It is easier than ever to create a single interface for
your app that works well on both iPad and iPhone, adjusting to
orientation changes and different screen sizes as needed. Design apps
with a common interface and then customize them for different size
classes. Adapt your user interface to the strengths of each form
factor. You no longer need to create a specific iPad storyboard;
instead target the appropriate size classes and tune your interface
for the best experience.
There are two types of size classes in iOS 8: regular and compact. A
regular size class denotes either a large amount of screen space, such
as on an iPad, or a commonly adopted paradigm that provides the
illusion of a large amount of screen space, such as scrolling on an
iPhone. Every device is defined by a size class, both vertically and
horizontally. iPad size classes shows the native size classes for the
iPad. With the amount of screen space available, the iPad has a
regular size class in the vertical and horizontal directions in both
portrait and landscape orientations.
Edit:
It only supports iOS 8(backward compatible applies only for iOS 7) and later.
You've got to create to separate storyboards for each kind of device. If you would delete the iPad storyboard, than your app would use the iPhone's one. You'll realize it when you'll see the 2x button at the bottom of the screen. Everything will be scaled to fit the larger screen - and the graphics would be really bad.
The only suitable workaround is to copy-paste everything from your iPhone Storyboard to iPad storyboard. Just follow the next steps:
Open iPhone.storyboard,
Press CMD+A,
Press CMD+C,
Switch to iPad.storyboard,
Press CMD+V,
You'll see, that all the screens, segues, properties and actions are transferred to your new storyboard. All that you have to do is to fix the frames of all your elements so that they'll suit new screen sizes.
And don't forget, that a good iPad application shouldn't be the same as the iPhone version. There are a lot of cool things which you can do with iPad!

Resources