Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

float:left in objective-c

I'm trying to make a bunch of buttons behave somewhat like float:left in CSS. So whenever the view changes size, on orientation change for example, the buttons should adjust so they fit within their container view.

In landscape mode, this UIScrollView should scroll horizontally, in portrait mode, it should scroll vertically.

I'm trying to make an ScrollView similar to the "Featured" tab in the iPad YouTube app. Landscape has 4 columns, portrait: 3 columns, "Subscriptions" tab, portrait, the same view has 2 columns.

alt text

like image 775
TD540 Avatar asked Jan 10 '11 17:01

TD540


2 Answers

I have implemented a layout system to do things like this. There is a demo project on how to use it checked into that repository. I'd be happy to answer any questions about it. This is much more lightweight than AQGridView, so if you don't need the extra functionality he is providing, I would recommend an approach similar to mine.

like image 199
Joshua Weinberg Avatar answered Sep 20 '22 13:09

Joshua Weinberg


you might want to check out AQGridView, which is basically a re-implementation of Cocoa's NSCollectionView: https://github.com/AlanQuatermain/AQGridView

Otherwise, you might need to override layoutSubviews in your parentView and then rearrange the subviews (buttons) accordingly when the dimensions of the parentView change.

Cheers,

Johannes

like image 33
Johannes Fahrenkrug Avatar answered Sep 20 '22 13:09

Johannes Fahrenkrug