4
votes

enter image description here

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:

enter image description here

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.

2
Sounds like something that would be possible with auto layout - Chris Byatt
Probably the easiest way of doing this is UICollectionView. - Fogmeister
"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" Yup, that is why I carefully said in my answer that I was talking about an iPhone app. Lack of a size class difference for iPad orientations is a curious shortcoming at this stage of the beta process. - matt

2 Answers

3
votes

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.

-2
votes

With UICollectionView you can set up layout like CSS float.