自定义TableViewCell
来源:互联网 发布:进入数据库命令 编辑:程序博客网 时间:2024/05/18 05:17
自定义TableViewCell 布局有很多种,个人建议简单的cell使用第一种,复杂的用第二种。除此之外还有很多种实现方法,但是从代码重用的角度来说不是很好,没有写的必要。
言归正传:
1) 程序默认带有一个 ImageView , 一个textLabel, 一个DetailLabel, 和一个accessoryView,如果不需要过多的其它控件,可以创建一个UITableViewCell的子类。在 -(void)layoutSubviews 方法中改变这些子视图的Frame即可,比如:
01
#import "MyCell.h"
02
03
@implementation MyCell
04
05
/*这里定义Frame*/
06
07
-(
void
)layoutSubviews{
08
09
self.imageView.frame =CGRectMake(0.0f, 0.0f, 50.0f, 50.0f);
10
11
self.textLabel.frame =CGRectMake(60.0f, 0.0f, 100.0f, 20.0f);
12
13
self.detailTextLabel.frame =CGRectMake(60.0f, 25.0f, 150.0f, 20.0f);
14
15
self.accessoryView.frame =CGRectMake(280.0f, 10.0f, 30.0f, 30.0f);
16
17
}
2) 如果cell内容过于复杂,可以自己定义属性,比如:
1
#import <UIKit/UIKit.h>
2
3
@interface MyCell : UITableViewCell
4
5
@property (nonatomic,retain) UILabel *nameLabel;
6
@property (nonatomic,retain) UILabel *sexLabel;
7
@property (nonatomic,retain) UILabel *ageLabel;
8
9
@end
01
#import "MyCell.h"
02
03
@implementation MyCell
04
05
@synthesize nameLabel,sexLabel,ageLabel;
06
07
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
08
{
09
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
10
if
(self) {
11
// Initialization code
12
nameLabel =[[UILabel alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
13
sexLabel =[[UILabel alloc]initWithFrame:CGRectMake(60.0f, 0.0f, 100.0f, 20.0f)];
14
ageLabel = [[UILabel alloc]initWithFrame:CGRectMake(60.0f, 25.0f, 150.0f, 20.0f)];
15
}
16
return
self;
17
}
18
- (
void
)dealloc
19
{
20
self.nameLabel =nil;
21
self.sexLabel =nil;
22
self.ageLabel =nil;
23
[super dealloc];
24
}
- 自定义TableviewCell
- 自定义TableViewCell
- 自定义tableViewcell
- 自定义TableViewcell
- 自定义TableViewCell的使用方法
- 自定义tableviewcell(一)
- 自定义tableviewcell(二)
- TableViewCell组件的自定义
- ios 自定义tableviewcell
- iOS 自定义tableViewcell
- TableViewCell自定义分割线
- TableViewCell自定义分割线
- 笔记--8.29(自定义tableViewCell)
- 自定义TableViewCell内容
- TableViewCell自定义分割线
- ios 自定义tableViewcell,UITableViewCell
- Swift实现自定义TableViewCell
- 自定义cell,tableviewcell
- Centos6.4错误的修改了rc.local无法启动系统解决方案
- IOS UITableView 移动自定义cell
- Apache Math研读
- IOS开发之协议和代理
- 初学者学Java(十四)
- 自定义TableViewCell
- JavaScript 操作 Cookie
- osal_start_system运行操作系统函数
- 9/29-10/6待字闺中面试题练习
- HDU 4768 Flyer(13年长春网络赛-J题-二分)
- 经验总结
- url、httprequest、request使用详解
- Linux内核系统定时器TIMER实现过程分析
- eclips 隐藏QuickAccess