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











    让过去成就未来.
  • 相关阅读:
    小、快、简、易、强的“银弹”— fastm
    使用Creative suite 3和Flex Builder3实现Flex 3的换肤
    Apache HTTP Server 与 Tomcat 的三种连接方式介绍
    iframe自动适应付窗口的大小变换
    Flash网络游戏开发入门经验共享
    比较详细的 Linux Top 命令解析
    HttpContext是干什么的
    asp.net,cookie,写cookie,取cookie 的方法
    为什么我们不要 .NET 程序员
    在Ubuntu上安装使用深度影音&深度音乐(推荐)
  • 原文地址:https://www.cnblogs.com/mkr127/p/5490728.html
Copyright © 2011-2022 走看看