Advertisement
Guest User

UI collection view

a guest
Oct 28th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)viewDidLoad
  2. {
  3.     [super viewDidLoad];
  4.     // Do any additional setup after loading the view, typically from a nib.
  5.     UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
  6.     _collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(130, 100, 780, 1024) collectionViewLayout:layout];
  7.     _collectionView.autoresizesSubviews= YES;
  8.     [_collectionView setDataSource:self];
  9.     [_collectionView setDelegate:self];
  10.     _collectionView.backgroundColor = [UIColor clearColor];
  11.    
  12.     [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
  13.    
  14.     [self.view addSubview:_collectionView];
  15.     for (int i=0; i<12; i+=2) {
  16.         NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
  17.         NSIndexPath *index1 = [NSIndexPath indexPathForItem:i+1 inSection:0];
  18.         [_collectionView moveItemAtIndexPath:index toIndexPath:index1];
  19.     }
  20.     for (int i=2; i<12; i+=2) {
  21.         NSIndexPath *index = [NSIndexPath indexPathForItem:i inSection:0];
  22.         NSIndexPath *index1 = [NSIndexPath indexPathForItem:i+1 inSection:0];
  23.         [_collectionView moveItemAtIndexPath:index toIndexPath:index1];
  24.     }
  25.      
  26.    
  27. }
  28.  
  29. - (void)didReceiveMemoryWarning
  30. {
  31.     [super didReceiveMemoryWarning];
  32.     // Dispose of any resources that can be recreated.
  33. }
  34. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  35. {
  36.     return 12;
  37. }
  38. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  39. {
  40.     return 1;
  41. }
  42. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  43. {
  44.     UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
  45.    
  46.     // code for customising the cell....
  47.     cell.layer.shadowColor = [[UIColor blackColor]CGColor];
  48.     cell.layer.shadowOffset = CGSizeMake(20, 20);
  49.     cell.layer.borderColor = [[UIColor blackColor] CGColor];
  50.     cell.layer.borderWidth =1;
  51.     cell.alpha = 0;
  52.    
  53.    
  54.    
  55.     return cell;
  56. }
  57. -(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  58. {
  59.     return 10;
  60. }
  61. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  62. {
  63.     return CGSizeMake(377, 172);
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement