UICollectionView的簡單使用

2021-06-28 21:25:07 字數 1452 閱讀 1673

所屬controller要遵循三個協議:uicollectionviewdatasource,uicollectionviewdelegate,uicollectionviewdelegateflowlayout

uicollectionviewflowlayout *flowlayout = [[uicollectionviewflowlayout alloc]init];

[flowlayout setitemsize:cgsizemake(70, 100)];//設定cell的尺寸

[flowlayout setscrolldirection:uicollectionviewscrolldirectionvertical];//設定其布局方向

flowlayout.sectioninset = uiedgeinsetsmake(5, 5, 5, 5);//設定其邊界

//其布局很有意思,當你的cell設定大小後,一行多少個cell,由cell的寬度決定

_collectionview = [[uicollectionview alloc]initwithframe:cgrectmake(0, 0, 320, self.view.frame.size.height) collectionviewlayout:flowlayout];

_collectionview.datasource = self;

_collectionview.delegate = self;

_collectionview.backgroundcolor = [uicolor clearcolor];

[_collectionview registerclass:[bmcollectioncell class] forcellwithreuseidentifier:cell_id];

[self.view addsubview:_collectionview];

[_collectionview release];

//collectionview的**方法

-(nsinteger)collectionview:(uicollectionview *)collectionview numberofitemsinsection:(nsinteger)section

-(nsinteger)numberofsectionsincollectionview:(uicollectionview *)collectionview

-(uicollectionviewcell )collectionview:(uicollectionview )collectionview cellforitematindexpath:(nsindexpath *)indexpath

{ bmcollectioncell *cell = [collectionview dequeuereusablecellwithreuseidentifier:cell_id forindexpath:indexpath];

UICollectionView 簡單使用

當然在橫向布局的時候需要注意的是uicollectionview 的高度。如果高度設定不合理就不能顯示出橫向滾動的效果。布局例項可以在例項化的時候就設定好相應的顯示效果也可以通過 uicollectionviewdelegateflowlayout 協議靈活實現。四 協議 uicollectionv...

UICollectionView的無縫排序

歡迎光臨我的 有些東西不去用,總是學不會,所以這就想到一直的知識盲點,uicollectionview 每次使用的時候,都是控制不好cell的間隔 於是在整理過後知道了,collection view 是通過uicollectionviewflowlayout來控制cell的間隔 通常情況下設定 c...

BGAQRCode Android的簡單使用

compile com.google.zxing core 3.2.1 xmlns android 這句是使用選擇器框架時用到的 xmlns tools package com.huaqiang.zxingdemo 選擇框架用到 android name android.permission.cam...