IOS different xibs for different screen sizes - ios

I am new to IOS programming and would like to display a square image in a UITableViewCell, so size would be 320x320 or 375x375 for iphones 5 and 6 for instance.
Can this be done with a single xib file or two different XIB?
If it's 2 XIB, what is a good screen size test for registering the correct nib as a tableview cell?

You can use single XIB using AutoLayout and Adaptative Layout provided by the Size Classes : Apple Doc.
Size Classes allow you to deal with different sizes. [Regular] - [Compact]
You should found here what you are looking for.

You can do this in a single xib. Using autolayout, you have to add a constraint to specify that your cell's height should be the same as its width. This way, if the width changes your height is automatically updated.

Related

How to have different layouts for iPhone and iPad (Swift)

In an app that I use, there are 4 rows of buttons with each row containing 3 buttons. When I use the same app on an iPad, the alignment of the buttons becomes 2 rows containing 6 buttons each. Also, the width and height of the buttons change depending on the screen size. I want my app to have the same features but I don't know how to do it. Any help?
1) You can use Autolayout constraints and size classes to make the view compatible to both iPhone and iPad screen sizes.
2) You can create and use separate Storyboards or .Xibs each for iPhone and iPad and use accordingly.
3) if the view does not have complex UI, then you can simply manage by doing it via code by detecting the view size, width height etc i.e whether it is iphone or iPad and then setting the frame, width, height of the UIElements like button, label, image view etc.
You need to use size classes. Following is the link which helps you to understand size classes :
Size Classes or Adaptive layout
Use Autolayout for defining constraints on buttons.
There might be two cases :
Either you want your buttons to be of the same height/width; In this case, you can define the height and width constraints to your buttons.
Or you want the buttons to be bigger. For that, you can define autolayout constraints in code if the screen size is for iPad.

Use size classes to create different cells for uitableview cell xib

I am using xib to design the UI for my tableview cell. My app is universal. right now i am using 2 different xib files. one for iphone cell and one for ipad cell.
I am wondering if its possible to use only one xib file and use size class to create UI for tableview cell for iphone and ipad.
I tried it but the problem i am facing is, when i change the size class from regular height and regular width and then change the height and width of xib the same height and width appear in any height any width size class and vice versa. thus i am not able to keep the constraints properly

is it possible to set different heights of cells in Sizeclasses for differnt devices?

i want to set different heights in my TableView.
On iPad i want 100 and on iPhone 70.
In addition, on iPhone i want to move/delete some UIElements.
My question is: is it possible to do that when using sizeclasses just in storyboards? No code adaption if possible.
So on iPhone i want also to set a different font size. In short words, i want to use ONE Storyboard file with SizeClass and in THIS ONE Storyboard file, i want to set all constraints.
When i am changing the height of a cell for iPhone in storyboard, iPad changes, too.
Whats your recommendation? Is it possible ONLY with SizeClasses? Or should i create a seperate Storyboard for iPhone?

How to change the width of the UITablewViewCell with autolayout?

In one of my tableview i'm using a custom view created with a XIB file.
The tableview is correctly resized with autolayout, but the width of the cell is fixed.
In particular i saw that the ContentView is fixed to 320 px (the size used on the xib file).
Is there a way to use autolayout to change this value?
Sounds like you haven't set any constraints in your custom cells. The cell itself isn't the problem I guess, usually the container view is. So lets say you created the cell to fit the iPhone and it looks cut off on iPad, it most certainly because the UILabel or UITextView or any other element in the XIB isn't configured to stretch according to its constraints.
There's this beautiful tutorial by ray wenderlich, if you wanna learn more about auto-layout and how constraints secure that your app looks good on any device
If you need further help, just let me know!

Float layout in interface builder in iOS?

I want add one UIView – which has various number of UILabel objects – to a UIViewController.
How is it possible to set up constrains via auto-layout so, that if rotation occurs, and view width decrease, than height should increase, and labels should fit in like below, as CSS float do it.
Is it possible with interface builder and not programmatically?
UPDATE
Meantime I experimented iOS8 new interface builder feature called Size Classes (WWDC 2014 What's New in Interface Builder from 29:59), as matt has recommended down. But as I see, it supports something different, that I am looking for. Size Classes aim is to put different xibs (iPhone, iPad) into one xib, to have one xib instead of more.
In my case it does not help. What I have done to set up different auto-layout constrains for these two size classes:
But when I was running the application in iPad 4 simulator - what is the main target for my app - it used always the regular width / any height size class, and never the any width / any height, what my original expectation would have.
I do not know what "in a floating way" means. But in Xcode 6 you can easily do what you're describing, changing the constraints in an iPhone app so that the fourth label drops down to the next line, using the new conditional constraints (size classes) feature. With this feature, you can have one set of constraints for one set of size classes (e.g. iPhone in landscape) and another for a different set of size classes (e.g. iPhone in portrait).
Prior to Xcode 6, the answer would be no, you can't do that using IB alone. Code of some sort, whether a collection view or your own code responding to rotation/layout, would have to change the constraints.
With UICollectionView you can set up layout like CSS float.

Resources