Skip to content

Instantly share code, notes, and snippets.

@keisukeYamagishi
Last active January 15, 2017 08:04
Show Gist options
  • Save keisukeYamagishi/9e1f46c5de8827b9aa780a91c51e0656 to your computer and use it in GitHub Desktop.
Save keisukeYamagishi/9e1f46c5de8827b9aa780a91c51e0656 to your computer and use it in GitHub Desktop.
//
// ViewController.h
// collectionView
//
// Created by tomyAmi on 2014/10/11.
// Copyright (c) 2014年 tomyAmi. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface collectionController : UIViewController
@end
82 lines (63 sloc) 2.04 KB
//
// ViewController.m
// collectionView
//
// Created by tomyAmi on 2014/10/11.
// Copyright (c) 2014年 tomyAmi. All rights reserved.
//
#import "ViewController.h"
@interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>
@end
UICollectionView *_main;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
int wid=self.view.frame.size.width;
/**
* コレクションビューのレイアウト
*/
UICollectionViewFlowLayout *rayout=[[UICollectionViewFlowLayout alloc]init];
rayout.minimumInteritemSpacing=2.0f;
rayout.minimumLineSpacing=2.0f;
rayout.itemSize=CGSizeMake(wid/3-2.0f, wid/3-2.0f);
/**
* コレクション
*/
_main=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, (self.view.frame.size.height)-44) collectionViewLayout:rayout];
_main.delegate=self;
_main.dataSource=self;
[_main registerClass:[UICollectionViewCell class]forCellWithReuseIdentifier:@"UICollectionViewCell"];
[self.view addSubview:_main];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/**
* セルの数
*
* @param collectionView
* @param section
*
* @return
*/
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 100;
}
/**
* セルを返す
*
* @param collectionView
* @param indexPath
*
* @return
*/
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *cellId=@"UICollectionViewCell";
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
UIImageView *celImage =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"beauty.jpg"]];
cell.backgroundView = celImage;
return cell;
}
@keisukeYamagishi
Copy link
Author

add header file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment