UICollectionViewController简单操作
2015-06-24 13:46
441 查看
// // MyCollectionViewCell.h // AppUI组件学习 // // Created by 麦子 on 15/6/24. // Copyright (c) 2015年 麦子. All rights reserved. // #import <UIKit/UIKit.h> @interface MyCollectionViewCell : UICollectionViewCell @property(nonatomic,strong)UILabel *label; @end
// // MyCollectionViewCell.m // AppUI组件学习 // // Created by 麦子 on 15/6/24. // Copyright (c) 2015年 麦子. All rights reserved. // #import "MyCollectionViewCell.h" @implementation MyCollectionViewCell @synthesize label; - (instancetype)initWithFrame:(CGRect)frameA{ self = [super initWithFrame:frameA]; if (self) { self.backgroundColor = [UIColor orangeColor]; label = [[UILabel alloc] init]; label.frame = CGRectMake(25, 35, 50, 30); label.backgroundColor = [UIColor purpleColor]; [self addSubview:label]; } return self; } @end
// // MyCollectionViewController.m // AppUI组件学习 // // Created by 麦子 on 15/6/24. // Copyright (c) 2015年 麦子. All rights reserved. // #import "MyCollectionViewController.h" #import "MyCollectionViewCell.h" @interface MyCollectionViewController () @end @implementation MyCollectionViewController static NSString * const reuseIdentifier = @"Cell"; - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.title = @"集合视图"; // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = NO; // 注册这个 [self.collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark <UICollectionViewDataSource> // 分区 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } // 一个区有多少行 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 10; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; cell.label.text = [NSString stringWithFormat:@"%ld",indexPath.row]; cell.label.textColor = [UIColor redColor]; cell.label.textAlignment = NSTextAlignmentCenter; return cell; } #pragma mark <UICollectionViewDelegate> /* // Uncomment this method to specify if the specified item should be highlighted during tracking - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } */ /* // Uncomment this method to specify if the specified item should be selected - (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath { return YES; } */ /* // Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item - (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath { return NO; } - (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender { return NO; } - (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender { } */ @end
// 集合视图 // 创建流逝布局 UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init]; // 单元格大小 flow.itemSize = CGSizeMake(100, 100); // 滚动的方向 flow.scrollDirection = UICollectionViewScrollDirectionVertical; // 设置边界 flow.sectionInset = UIEdgeInsetsMake(40, 0, 0, 0); MyCollectionViewController *collectionDemo = [[MyCollectionViewController alloc] initWithCollectionViewLayout:flow];
相关文章推荐
- 使用Xib创建UICollectionView
- UICollectionView 与 storyboard 的一点体会
- IOS-—UICollectionView使用综述(一 )(基础篇--垂直列表方式,横向相册方式)
- iOS开发之高级视图—— UICollectionViewController
- 使用iOS控件UICollectionView生成可拖动的桌面
- 自定义UICollectionViewController之后如何设置布局方式
- UICollectionViewController简单操作(2)
- ios UICollectionViewController集合视图(一)
- ios UICollectionViewController集合视图(二)
- 有关UICollectionviewController的一些问题
- iOS UICollectionViewController基本使用方法和简单的相册实现
- Convert boolean values to strings 'Yes' or 'No'.
- suid位,sgid位及setuid(),setgid()函数实测情况
- XCUIElementType API
- UITableView的上下滑动与自己添加的手势冲突
- poj2778 DNA Sequence(AC自动机+矩阵快速幂 )
- 比较height(),innerHeight(),outerHeight()和outerHeight(true)
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content
- UIBezierPath 的理解 及使用
- Android API Guides - Activities - Fragments