您的位置:首页 > 产品设计 > UI/UE

iOS UICollectionView学习之一,UICollectionView + storyboard 简单应用

2014-12-29 14:14 507 查看

iOS UICollectionView + storyboard 的应用

1.新建一个项目Single View Application

2.选中项目中的storyboard ,并且直接往空白页面上拖拽一个 collectionView,并设置相关属性



关联代理









3、创建一个继承 UICollectionViewCell 的类



4.关联类,以及添加标识。





5.上面基本控件已经拖拉完成,接下来就是做印射(输出口),并且添加相应的代码即可





6.在控制器上添加代码。.h中导入协议

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UICollectionViewDelegate,UICollectionViewDataSource>

@property (strong, nonatomic) IBOutlet UICollectionView *myCollectionV;

@end

.m 里面

#import "ViewController.h"

#import "myCollectionViewCell.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

}

#pragma mark ---UICollectionView DataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

return 20;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identify = @"myCell";

myCollectionViewCell *cell = (myCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];

cell.titleImageV.image = [UIImage imageNamed:@"LOGO80-80"];

cell.titleLable.text = [NSString stringWithFormat:@"{%ld,%ld}",indexPath.section,indexPath.row];

return cell;

}

7.效果图



每天进步一点点,做一个快乐的程序猿;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: