UI 09 自定义cell
2015-08-29 10:54
441 查看
我们能够发现系统的cell有时候不能够满足我们的要求, 这时候我们就需要自定义属于我们的cell
新建一个继承于UITableViewCell 文件.
注意, cell的属性名字绝对不能够和系统的一样
在.m中有两个方法, 一个是初始化, 一个是layOutViews
新建一个继承于UITableViewCell 文件.
注意, cell的属性名字绝对不能够和系统的一样
#import <UIKit/UIKit.h> @interface ThreeANDTwoTableViewCell : UITableViewCell @property(nonatomic, retain)UIImageView *imageviewOne; @property(nonatomic, retain)UIImageView *imageviewTwo; @property(nonatomic, retain)UIImageView *imageviewThree; @property(nonatomic, retain)UILabel *leftLabel; @property(nonatomic, retain)UILabel *rightLabel; @end
在.m中有两个方法, 一个是初始化, 一个是layOutViews
#import "ThreeANDTwoTableViewCell.h" #define WIDTH self.contentView.frame.size.width #define HEIGHT self.contentView.frame.size.height @implementation ThreeANDTwoTableViewCell - (void)dealloc{ [_imageviewOne release]; [_imageviewThree release]; [_imageviewTwo release]; [_leftLabel release]; [_rightLabel release]; [super dealloc]; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self creatViews]; } return self; } - (void)creatViews{ // 再初始化中不设置fram self.imageviewOne = [[UIImageView alloc] init]; self.imageviewOne.backgroundColor = [UIColor cyanColor]; [self.contentView addSubview:self.imageviewOne]; [_imageviewOne release]; self.imageviewTwo = [[UIImageView alloc] init]; self.imageviewTwo.backgroundColor = [UIColor cyanColor]; [self.contentView addSubview:self.imageviewTwo]; [_imageviewTwo release]; self.imageviewThree = [[UIImageView alloc] init]; self.imageviewThree.backgroundColor = [UIColor cyanColor]; [self.contentView addSubview:self.imageviewThree]; [_imageviewThree release]; self.leftLabel = [[UILabel alloc] init]; self.leftLabel.backgroundColor = [UIColor orangeColor]; [self.contentView addSubview:self.leftLabel]; self.leftLabel.textAlignment = NSTextAlignmentCenter; [_leftLabel release]; self.rightLabel = [[UILabel alloc] init]; self.rightLabel.backgroundColor = [UIColor cyanColor]; [self.contentView addSubview:self.rightLabel]; self.rightLabel.textAlignment = NSTextAlignmentCenter; [_rightLabel release]; } - (void)layoutSubviews{ // 一定不要遗忘super! [super layoutSubviews]; self.imageviewOne.frame = CGRectMake(0, 0,WIDTH/3, HEIGHT/3*2); self.imageviewTwo.frame = CGRectMake(WIDTH/3, 0, WIDTH/3, HEIGHT/3*2); self.imageviewThree.frame = CGRectMake(WIDTH/3*2, 0, WIDTH/3, HEIGHT/3*2); self.leftLabel.frame = CGRectMake(0, HEIGHT/3*2, WIDTH/2, HEIGHT/3); self.rightLabel.frame = CGRectMake(WIDTH/2, HEIGHT/3*2, WIDTH/2, HEIGHT/3); }
相关文章推荐
- 《第一行代码》读书笔记(二)----UI开发(上)
- 野人学Android基础篇之初探UI控件第六课--ListView和他的adapter们(一)
- UI 09 tableView 中国省市区. 一个页面, 三个tableView
- UI 08 tableView版中国省市区 -- 3页
- UI tableView 的头视图 & "小广告"
- Win10正式版怎么删除搜狗输入法中的SogouExe顽固文件?
- UVA 1605 Building for UN
- UI 07 界面传值 之 从后向前 ---- 协议传值
- HDU 5147 Sequence II (线段树求前缀和、后缀和)
- UIView的alpha、hidden和opaque属性之间的关系和区别
- C#基础----string和stringBuilder
- Win10 10525升级Win10 Build 10532失败回滚怎么办?
- POJ 3080 Blue Jeans(水~)
- 单行文本框和多行文本框UiTextfield UiTextView
- POJ 2871 A Simple Question of Chemistry(水~)
- POJ 2785 4 Values whose Sum is 0(hash表)
- 从数据库中提取到ueditor并且重新编辑
- POJ 2664 && HDU 1144 Prerequisites?(水~)
- 【LeetCode-面试算法经典-Java实现】【225-Implement Stack using Queues(用队列实现栈操作)】
- 6、iOS 开发之 UIPickerView