Skip to content

Instantly share code, notes, and snippets.

@dutran90
Created August 18, 2015 15:49
Show Gist options
  • Save dutran90/66d4fa528789d00f55a5 to your computer and use it in GitHub Desktop.
Save dutran90/66d4fa528789d00f55a5 to your computer and use it in GitHub Desktop.
UICollectionView
#pragma mark - Process data
- (CGFloat) calculateWidthItem{
return ([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2;
}
- (CGFloat) calculateHeightItem{
return (([[UIScreen mainScreen]bounds].size.width -16 - 4*10)/2)*1.5;
}
--> widthItem = [self calculateWidthItem];
heightItem = [self calculateHeightItem];
seperator = 10.0f;
#pragma mark - UICollectionView Delegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return arrayPost.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(widthItem, heightItem);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return seperator;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return seperator;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(seperator, seperator, seperator, seperator);
}
-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if (!nibCustomCellLoaded) {
UINib *nib = [UINib nibWithNibName:@"CCGridPostImage" bundle:nil];
[collectionView registerNib:nib forCellWithReuseIdentifier:@"CCGridPostImage"];
nibCustomCellLoaded = YES;
}
CCGridPostImage *cell = (CCGridPostImage*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CCGridPostImage" forIndexPath:indexPath];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}
//LOAD MORE
#pragma mark - UIScroll Delegate
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
// UITableView only moves in one direction, y axis
CGFloat currentOffset = scrollView.contentOffset.y;
CGFloat maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height;
//NSInteger result = maximumOffset - currentOffset;
// Change 10.0 to adjust the distance from bottom
if (currentOffset - maximumOffset > 10) {
skip = skip + limit;
[self getArrPostWithLimit:limit andSkip:skip];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment