ios中重写CollectionViewCell
来源:互联网 发布:manifest.json 编辑:程序博客网 时间:2024/05/22 18:22
RZMars个人Blog地址: http://www.rzmars.com
在IOS6中添加了许多新的API,UICollectionView 也就是UITableView的亲弟弟可能是最热的了今天我们就来说一说在UICollectionView中最为重要的一个对象UICollectionViewCell的重写来侃侃:更多内容请登陆 www.rzmars.com
UICollectionViewCell 继承于UICollectionReusableView(继承UIView)
在UICollectionViewCell中最要的就是@property (nonatomic, readonly) UIView *contentView; // add custom subviews to the cell’s contentView这个属性了 因为我们平常到是self.view 来添加子控件 这次要用contentView来添加了:
重写的方式大同小异就不多说了 直接贴上代码:
MyCollectionView.h文件:
#import <UIKit/UIKit.h>
@interface MyCollectionView : UICollectionViewCell
-(void)setImage:(UIImage*)image;
-(void)setImgTitle:(NSString *)tiitle;
-(void)setImageTitleLabelWidth:(CGFloat)width withHight CGFloat)hight;
-(void)setimageTitleTextColor:(UIColor *)bgColor withTextColor:(UIColor *)textColor;
@end
MyCollectionView.m 文件:
//
// MyCollectionView.m
// CollectionViewCellDemo
//
// Created by RZMars on 10/17/13.
// Copyright (c) 2013 RZMars. All rights reserved.
//
#import “MyCollectionView.h”
@interface MyCollectionView ()
@property(strong,nonatomic) UIImageView * _mImage;
@property(strong,nonatomic) UITextView * _mTextView;
@end
@implementation MyCollectionView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self._mImage = [[UIImageView alloc] initWithFrame:CGRectMake(0., 0., frame.size.width, frame.size.height)];
}
return self;
}
-(void)setImage:(UIImage*)image{
self._mImage.image=image;
}
-(void)setImgTitle:(NSString *)tiitle{
if([self.contentView subviews]){
for ( UILabel *subView in [self.contentView subviews] ) {
[subView removeFromSuperview];
}
}
[self.contentView addSubview:self._mImage];
[self._mTextView setText:tiitle];
[self.contentView addSubview:self._mTextView];
}
-(void)setImageTitleLabelWidth:(CGFloat)width withHight CGFloat)hight{
self._mTextView =[[UITextView alloc] initWithFrame:CGRectMake(20, self._mImage.frame.size.height/2+18, width, hight)];
self._mTextView.contentInset=UIEdgeInsetsMake(1, 1, 1, 1);
self._mTextView.userInteractionEnabled=NO;
}
-(void)setimageTitleTextColor:(UIColor *)bgColor withTextColor:(UIColor *)textColor{
self._mTextView.textColor = textColor;
self._mTextView.backgroundColor= bgColor;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
使用:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MyCollectionView * imgView =[[MyCollectionView alloc] initWithFrame:CGRectMake(10, 50, 100, 100)];
[imgView setImage:[UIImage imageNamed:@"logo"]];
[imgView setImageTitleLabelWidth:60 withHight:30];
[imgView setimageTitleTextColor:[UIColor redColor] withTextColor:[UIColor greenColor]];
[imgView setImgTitle:@"RZMars"];
[self.view addSubview:imgView];
}
好了 是不是很简单? 下节我们将学习UITableView的亲弟弟的使用!!!!!
バイバイ
- ios中重写CollectionViewCell
- iOS中collectionViewCell显示不正确的问题
- iOS collectionViewCell拖动动画
- iOS CollectionView加载xib CollectionViewCell
- iOS开发之 CollectionViewCell 无法加载
- ios 取到collectionviewcell的动态位置
- tableViewCell中嵌套collectionViewCell 显示异常
- iOS 中hash的重写
- IOS开发之CollectionViewCell重用产生重叠的处理方法
- ui--CollectionViewCell
- iOS之实现按钮拖动/tableViewcell多选,拖动/collectionviewcell多选,拖动(交换位置)
- 可移动的CollectionViewCell
- collectionview 边距 collectionViewCell圆角
- Swift CollectionViewCell重排
- iOS UITextField重写
- iOS UIButton的重写
- iOS方法重写
- iOS 重写isEqual方法
- Fragment初识
- JavaSE基础学笔记-内部类
- 01背包问题-----回溯法的解决方案
- win7环境下cocos2d-x2.1.4中创建工程
- 代理模式lua实现
- ios中重写CollectionViewCell
- android使用pull解析xml
- nyoj 27 水池数目
- ios中Tableview的两个获得重用cell方法的区别?(兼容iPhone5.0之前的版本)
- oracle中对时间的操作以及to_char和to_date用法总结
- WebService:设置服务器提供SOAP1.2的服务
- javascript脚本何时被执行
- sqoop的安装、配置及使用简介
- 把权限管理做到最好,把业务做到最好