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











    让过去成就未来.
  • 相关阅读:
    基于ArcGIS for Server的服务部署分析 分类: ArcGIS for server 云计算 2015-07-26 21:28 11人阅读 评论(0) 收藏
    ArcGIS for Server的安装及站点中的集群配置 分类: ArcGIS for server 2015-07-18 14:14 16人阅读 评论(0) 收藏
    Windows中的DNS服务——正向解析&反向解析配置 分类: AD域 Windows服务 2015-07-16 20:21 19人阅读 评论(0) 收藏
    如鹏网.Net高级技术8.反射
    如鹏网.Net高级技术6.正则表达式
    如鹏网.Net高级技术7.委托、事件
    如鹏网.Net高级技术5.泛型集合及键值对
    如鹏网.Net高级技术3.值类型和引用类型
    如鹏网.Net高级技术4.String特点及常用方法
    如鹏网.Net高级技术1.面向对象
  • 原文地址:https://www.cnblogs.com/mkr127/p/5490728.html
Copyright © 2011-2022 走看看