zoukankan      html  css  js  c++  java
  • UICollectionView

    1. //
    2. //  CollectionController.h
    3. //  MGuardian
    4. //
    5. //  Created by krmao on 16/5/13.
    6. //  Copyright © 2016年 krmao. All rights reserved.
    7. //
    8. #import <UIKit/UIKit.h>
    9. @interface CollectionController : UIViewController
    10. @end
    11. //********************************************************************************
    12. //*自定义类 UICollectionViewCell START
    13. //********************************************************************************
    14. //静态变量声明定义
    15. static NSString * __nonnull collectionCellID=@"mmcell";//可复用的reuseIdentifier
    16. @interface MCollectionItemCellView : UICollectionViewCell
    17. @property (weak, nonatomic) IBOutlet UILabel *mLabelView;
    18. + (MCollectionItemCellView * __nonnull)getCellView: (UICollectionView * __nonnull) uiCollectionView  index:(NSIndexPath * __nonnull)indexPath;
    19. @end
    20. //********************************************************************************
    21. //*自定义类 UICollectionViewCell 实现
    22. //********************************************************************************
    23. @implementation MCollectionItemCellView
    24. - (id __nonnull)initWithFrame:(CGRect)frame{
    25.    self=[super initWithFrame:frame ];
    26.    return self;
    27. }
    28. //静态工厂方法
    29. + (MCollectionItemCellView * __nonnull)getCellView: (UICollectionView * __nonnull) uiCollectionView  index:(NSIndexPath * __nonnull)indexPath;{
    30.    MCollectionItemCellView * cellView =(MCollectionItemCellView *) [uiCollectionView dequeueReusableCellWithReuseIdentifier:collectionCellID forIndexPath:indexPath];
    31.    //设置cell选中状态
    32.    //cellView.selectionStyle=UITableViewCellSelectionStyleDefault;
    33.    cellView.selectedBackgroundView=[[UIView alloc]initWithFrame:cellView.frame];
    34.    cellView.selectedBackgroundView.backgroundColor=[UIColor greenColor];
    35.    [cellView sizeToFit];
    36.    return cellView;
    37. }
    38. @end
    39. //********************************************************************************
    40. //*自定义类 UICollectionViewCell END
    41. //********************************************************************************
    1. //
    2. //  CollectionController.m
    3. //  MGuardian
    4. //
    5. //  Created by krmao on 16/5/13.
    6. //  Copyright © 2016年 krmao. All rights reserved.
    7. //
    8. #import "CollectionController.h"
    9. @interface CollectionController ()<UICollectionViewDataSource,UICollectionViewDelegate>
    10. @property (weak, nonatomic) IBOutlet UICollectionView *mCollectionView;
    11. @property NSMutableArray *dataList;
    12. @end
    13. @implementation CollectionController
    14. - (void)viewDidLoad {
    15.    [super viewDidLoad];
    16.    self.mCollectionView.dataSource=self;
    17.    self.mCollectionView.delegate=self;
    18.    self.dataList=[[NSMutableArray alloc]initWithObjects:   @"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",
    19.                                                            @"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z", nil];
    20. }
    21. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    22.    return self.dataList.count;
    23. }
    24. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    25.    MCollectionItemCellView *celView=[MCollectionItemCellView getCellView:collectionView index:indexPath];
    26.    celView.mLabelView.text=[NSString stringWithFormat: @"item:%i-%@",indexPath.row,[self.dataList objectAtIndex:indexPath.row]];
    27.    return celView;
    28. }
    29. @end











    让过去成就未来.
  • 相关阅读:
    2016-12-7
    使用netty4.x客户端接收较大数据量报文时发生的读取不完整bug修复记录
    AngularJS
    使用Netty收发二进制报文问题记
    如何在Linux中查看所有正在运行的进程
    面试连环炮系列(十四): HTTP状态码302的跳转逻辑
    算法天天练1:计算最长子串
    面试连环炮系列(十三):实现一个线程有几种方法
    面试连环炮系列(十二):说说Atomiclnteger的使用场景
    面试连环炮系列(十一):说说你们的分布式ID设计方案
  • 原文地址:https://www.cnblogs.com/mkr127/p/5490728.html
Copyright © 2011-2022 走看看