Objective--C UIScrollView 通讯录


东西太多了,为了以后好找,做个笔记........


创建工程,做好准备工作.将图片文件夹拖到工程中

创建一对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];

    

}



RootViewController.m下

- (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;

    }

    







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值