ios的collectionView區頭設定
直接上程式碼了:
#import "PhotoWallCell.h"
#import "ViewController.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
static NSString *collectionCellIndentider = @"collectionCellIndentider";
@interface ViewController ()
@property(nonatomic,weak)UICollectionView*collectionView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view addSubview:self.collectionView];
}
- (UICollectionView *)collectionView{
if (_collectionView) {
return _collectionView;
}
CGFloat collectionViewHeight = kScreenHeight - 190;
CGRect frame = CGRectMake(0, 150, kScreenWidth, collectionViewHeight);
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
//設定區頭的大小
layout.headerReferenceSize = CGSizeMake(320, 30);
//設定item大小
layout.itemSize =CGSizeMake(100, 100);
//設定區邊間距
layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
//設定最小間距
[layout setMinimumInteritemSpacing:10.0f];
[layout setMinimumLineSpacing:10.0f];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:layout];
collectionView.opaque = NO;
collectionView.backgroundColor = self.view.backgroundColor;
collectionView.dataSource = self;
collectionView.delegate = self;
collectionView.pagingEnabled = YES;
collectionView.showsVerticalScrollIndicator = NO;
collectionView.showsHorizontalScrollIndicator = NO;
[self.view addSubview:collectionView];
_collectionView = collectionView;
/*!
* @brief 註冊cell
*/
[collectionView registerClass:[PhotoWallCell class] forCellWithReuseIdentifier:collectionCellIndentider];
[collectionView registerClass:[PhotoWallCell class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider];
return collectionView;
}
#pragma mark -
#pragma mark -cell Delegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
PhotoWallCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:collectionCellIndentider forIndexPath:indexPath];
cell.backgroundColor =[UIColor yellowColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"你點選了");
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 6;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 3;
}
//設定session區頭內容
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader){
UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionCellIndentider forIndexPath:indexPath];
headerView.backgroundColor = [UIColor redColor];
//把想新增的控制元件放在session區頭重用的cell裡,並且回來賦值,防止重用(重點!!!!!)
UILabel *ttLabel = (UILabel *)[headerView viewWithTag:111];
SelectTypeM*mm =_allDate[indexPath.section];
ttLabel.text =mm.proportyName;
reusableview = headerView;
}
return reusableview;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
相關文章
- iOS CollectionView 的那些事iOSView
- [iOS]自定義UICollectionView 2-1–CollectionView的實現(定義與初始化)iOSUIView
- iOS - 二級連動(tableview包含 collectionview)iOSView
- iis主機頭的設定.
- iOS - Swift - TableView、CollectionView 空白佔點陣圖 EmptyDataSetiOSSwiftView
- iOS CollectionView FlowLayout與風火輪佈局 (二)iOSView
- 設定ExpandableListView右邊的箭頭View
- CollectionView 的異常View
- CollectionView 無限輪播設計思路View
- 改變aioserver的設定AIiOSServer
- ios橫屏設定iOS
- IOS-如何鎖定Xcode的API標頭檔案iOSXCodeAPI
- 設定openjdkdocker容器的時區JDKDocker
- MySQL中的時區設定MySql
- AFNetworking的請求頭設定(token)
- Excel如何設定列印區域?Exce列印區域設定教程Excel
- 抖音爆炸頭設定教程 抖音怎麼拍爆炸頭?
- idea檔案頭資訊設定Idea
- ios 設定啟動頁的那些坑iOS
- Django的時區設定問題Django
- ajax中設定請求頭和自定義請求頭
- CollectionView 佈局收集View
- iOS 產品新需求,要讓collectionView 的背景跟著Cell 一塊兒動!!!iOSView
- 更新TableView和CollectionView的狀態View
- iOS SVN忽略檔案設定iOS
- iOS圖片設定圓角iOS
- iOS-高效設定圓角iOS
- Docker映象時區設定Docker
- jvmlinux時區設定JVMLinux
- SAP設定時區資訊
- linux 時區設定Linux
- Azure Function 時區設定Function
- 今日頭條:iOS 架構設計雜談iOS架構
- IOS設定狀態列的背景顏色iOS
- 檢查BIOS具體的設定方法iOS
- iOS 設定的textFiled的時候不能編輯iOS
- win10重啟進bios設定的方法_win10怎麼進入bios設定Win10iOS
- 一個CollectionView 選單View