iOS自定义cell的写法
来源:互联网 发布:知乎live可以回看吗 编辑:程序博客网 时间:2024/05/24 16:13
<pre name="code" class="objc">自定义cell1.创建mycell继承于UITableviewcell2.在mycell.h中定义属性要添加的控件@property(nonatomic,retain)UIImageView *leftImageView;@property(nonatomic,retain)UILabel *upLabel;3.在mycell.m中释放-(void)dealloc{ [_downLabel release]; [_upLabel release];}4.自定义初始化- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self createView]; } return self;}5.-(void)createView{ self.leftImageView=[[UIImageView alloc] init]; self.leftImageView.backgroundColor=[UIColor orangeColor]; [self.contentView addSubview:self.leftImageView]; [_leftImageView release]; //创建有view self.rightImageView=[[UIImageView alloc] init]; self.rightImageView.backgroundColor=[UIColor orangeColor]; [self.contentView addSubview:self.rightImageView]; [_rightImageView release];}6.- (void)layoutSubviews{ [super layoutSubviews]; self.leftImageView.frame=CGRectMake(0, 0, WIDTH/3, HEIGHT); self.rightImageView.frame=CGRectMake(2*WIDTH/3, 0, WIDTH/3, HEIGHT); self.upLabel.frame=CGRectMake(WIDTH/3, 0, WIDTH/3, HEIGHT/2); self.downLabel.frame=CGRectMake(WIDTH/3, HEIGHT/2, WIDTH/3, HEIGHT/2);}7.mainControllerView中必执行协议中用自定义的cell创建cell-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *reuse=@"reuse"; MyCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse]; if (!cell) { cell=[[[MyCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease]; } cell.upLabel.text=self.arr[indexPath.row]; cell.leftImageView.image=[UIImage imageNamed:@"0.jpg"]; cell.rightImageView.image=[UIImage imageNamed:@"1.jpg"]; self.tabelView.rowHeight=100; return cell; }
0 0
- iOS自定义cell的写法
- ios 自定义cell cellForRowAtIndexPath中的写法
- 【iOS】自定义Cell的步骤
- iOS 自定义cell的高度
- iOS cell自适应 自定义cell
- iOS代码自定义UITableView Cell(每个Cell的高度不一样)
- ios 自定义cell右侧的图片显示
- iOS 8自定义cell的删除按钮
- iOS-自定义cell的方法步骤
- iOS--有关自定义Cell细线的问题
- IOS 自定义Cell的3种方式
- iOS 自定义不等高的cell
- iOS 自定义cell
- ios UITableview自定义cell
- IOS学习 Cell自定义
- ios 自定义cell demo
- iOS UI09_自定义cell
- IOS - 自定义cell
- 【鸟哥的linux私房菜-学习笔记】sed 工具
- Quick Start Guide for Apache Hawq[作者:盛想]
- Android文本输入框EditText方法说明和属性
- java synchronized详解
- mysql的行锁问题
- iOS自定义cell的写法
- 十年研发经验工程师的嵌入式学习书籍大推荐
- [maven2]maven2下pom.xml的json-lib的配置
- OpenMP: 使用OpenMP优化程序
- Introducing The Newly Redesigned Apache HAWQ [作者:常雷]
- 友元类和友元函数
- Leetcode-43-Multiply Strings C#
- appium的入门学习
- UITableView UITableViewStylePlain UITableViewStyleGrouped