LoginSignup
8
7

More than 5 years have passed since last update.

FKGridViewを使ってObjective-Cでグリッドレイアウト

Posted at

スクリーンショット 2014-03-05 13.45.15.png

jQueryのvgridの簡易的なものを再現したかったんですが、
色々ライブラリ探したんですけど手軽なのが無かったので作ってみました。

ソースコードは下記に格納しています。

https://github.com/fromkk/FKGridView

使い方は、

//initialize
self.gridView = [FKGridView new];
//set view frame
self.gridView.frame = self.view.bounds;
//set col counts
self.gridView.cols = 3;
//auto resize items.
self.gridView.autoresizeWidth = YES; //add subview
[self.view addSubview:self.gridView];

for (int i = 0; i < 102; i++) {
    //create subview
    UIView *currentView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, (320.0f - 5.0f * 4.0f) / 3.0f, rand() % 10 * 10.0f)];
    //red background color
    currentView.backgroundColor = [UIColor redColor];
    //add item. if animated is NO then stop animation.
    [self.gridView addGridItemView:currentView animated:YES];
}

UITableViewやUICollectionViewみたいに再利用に対応したいなと思ってはいるんですが、
とりあえず今回の案件ではそこまで負荷は掛からなそうだったのでビューを貼っつけるだけで対応しました。
カラム数を決め打ちにすると結構シンプルにいけそうだったので決め打ちで作ってます。

参照

8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7