东西太多了,为了以后好找,做个笔记........
创建工程,做好准备工作.将图片文件夹拖到工程中
创建一对CellView文件,在CellView.h中设置属性
@property(nonatomic,retain)UILabel *nameLabel;
@property(nonatomic,retain)UILabel *phoneLabel;
@property(nonatomic,retain)UIImageView *imageView;
@property(nonatomic,retain)UITextField *lowLine;
在CellView.m中铺界面格式
// 只要设置属性,就要写dealloc
- (void)dealloc
{
[_nameLabel release];
[_phoneLabel release];
[_imageView release];
[_lowLine release];
[super dealloc];
}
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self CellView];
}
return self;
}
- (void)CellView{
self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 50, 200, 50)];
self.nameLabel.layer.borderWidth = 1;
self.nameLabel.layer.cornerRadius = 8;
self.nameLabel.layer.masksToBounds = YES;
self.nameLabel.textAlignment = 1;
[self addSubview:self.nameLabel];
[_nameLabel release];
self.phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(160, 110, 200, 50)];
self.phoneLabel.layer.borderWidth = 1;
self.phoneLabel.layer.cornerRadius = 8;
self.phoneLabel.layer.masksToBounds = YES;
self.phoneLabel.textAlignment = 1;
[self addSubview:self.phoneLabel];
[_phoneLabel release];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 110)];
self.imageView.layer.borderWidth = 1;
self.imageView.layer.cornerRadius = 8;
self.imageView.layer.masksToBounds = YES;
[self addSubview:self.imageView];
[_imageView release];
self.lowLine = [[UITextField alloc] initWithFrame:CGRectMake(50, 170, 350, 1)];
self.lowLine.backgroundColor = [UIColor redColor];
[self addSubview:self.lowLine];
[_lowLine release];
}
- (void)dealloc
{
[_cellView release];
[_scrollView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 添加一个滚动视图
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
self.scrollView.backgroundColor = [UIColor whiteColor];
self.scrollView.pagingEnabled = YES;
self.scrollView.bounces = NO;
self.scrollView.showsHorizontalScrollIndicator = NO;
self.scrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:self.scrollView];
[_scrollView release];
// 将CellView添加到滚动视图上
for (NSInteger i = 1; i < 8; i++) {
self.cellView = [[CellView alloc] initWithFrame:CGRectMake(0, 150 *(i - 1), WIDTH, 0)];
self.cellView.backgroundColor = [UIColor redColor];
[self.scrollView addSubview:self.cellView];
[_cellView release];
self.cellView.tag = 1000 + i;
self.scrollView.contentSize = CGSizeMake(0, i * 160);
}
// 设置滚动范围
// 添加资料
for (NSInteger i = 1; i < 8; i++) {
// 添加头像
CellView *cellView = (CellView *)[self.view viewWithTag:1000 + i];
NSString *picName = [NSString stringWithFormat:@"h%ld.jpeg",i];
UIImage *image = [UIImage imageNamed:picName];
cellView.imageView.image = image;
// 添加练习人姓名
NSString *userName = [NSString stringWithFormat:@"张%ld",i];
cellView.nameLabel.text = userName;
// 添加电话号
NSString *phoneNumber = [NSString stringWithFormat:@"13%ldXXXXXXXX",i];
cellView.phoneLabel.text = phoneNumber;
}