当前位置:   article > 正文

iOS collectionView使用_ios coplectionview

ios coplectionview

  1. //布局
  2. UICollectionViewFlowLayout *flowRight = [[UICollectionViewFlowLayout alloc] init];
  3. [flowRight setItemSize:CGSizeMake(250, 227)];//(915-102)/3 = 271 650/2 = 325
  4. [flowRight setMinimumInteritemSpacing:1];
  5. [flowRight setMinimumLineSpacing:1];
  6. [flowRight setSectionInset:UIEdgeInsetsMake(5, 8, 0, 0)];
  7. [flowRight setScrollDirection:UICollectionViewScrollDirectionVertical];
  8. //collectView
  9. collectViewRight = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 15, 760, 230*3) collectionViewLayout:flowRight];
  10. collectViewRight.dataSource = self;
  11. collectViewRight.delegate = self;
  12. // [collectViewRight setContentSize:CGSizeMake(760, 230*4)];
  13. [collectViewRight setBackgroundColor:[UIColor whiteColor]];
  14. [collectViewRight registerClass:[fenleiDetailRightCell class] forCellWithReuseIdentifier:@"fenleiDetailRightCell"];
  15. [rightView addSubview:collectViewRight];
  16. [flowRight release];
  17. [collectViewRight release];
  18. //collect协议
  19. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  20. {
  21. if (collectionView ==collectViewRight) {
  22. static NSString *cellId = @"fenleiDetailRightCell";
  23. fenleiDetailRightCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
  24. cell.title.text = @"标题标题";
  25. cell.imageView.image = [UIImage imageNamed:@"ipad_bg_02"];
  26. [cell.bgView setImage:[UIImage imageNamed:@"ipad_bg_03"]];
  27. return cell;
  28. }else
  29. {
  30. static NSString *cellId = @"fenleiDetailLeftCell";
  31. fenleiDetailLeftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
  32. cell.title.text = @"标题标题";
  33. cell.imageView.image = [UIImage imageNamed:@"ipad_bg_02"];
  34. [cell.bgView setImage:[UIImage imageNamed:@"ipad_bg_03"]];
  35. return cell;
  36. }
  37. }
  38. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  39. {
  40. if (collectionView ==collectViewRight) {
  41. return 11;
  42. }
  43. else
  44. {
  45. return 12;
  46. }
  47. }

CELL

  1. #import "fenleiDetailRightCell.h"
  2. @implementation fenleiDetailRightCell
  3. - (id)initWithFrame:(CGRect)frame
  4. {
  5. self = [super initWithFrame:frame];
  6. if (self) {
  7. self.bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240, 220)];
  8. self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 220, 170)];
  9. self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, 180, 220 ,30)];
  10. [self.title setFont:[UIFont boldSystemFontOfSize:18]];
  11. [self.title setTextAlignment:NSTextAlignmentCenter];
  12. [self.title setBackgroundColor:[UIColor clearColor]];
  13. [self.bgView addSubview:self.imageView];
  14. [self.bgView addSubview:self.title];
  15. [self addSubview:self.bgView];
  16. [_imageView release];
  17. [_title release];
  18. }
  19. return self;
  20. }
  21. /*
  22. // Only override drawRect: if you perform custom drawing.
  23. // An empty implementation adversely affects performance during animation.
  24. - (void)drawRect:(CGRect)rect
  25. {
  26. // Drawing code
  27. }
  28. */
  29. -(void)dealloc
  30. {
  31. [_title release];
  32. [_bgView release];
  33. [_imageView release];
  34. [super dealloc];
  35. }
  36. @end

根据cell里面和layout修改间距


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/669544
推荐阅读
相关标签
  

闽ICP备14008679号