IOS开发之——私人通讯录自定义Cell和分割线(55)

一 概述

本文介绍自定义私人通讯录联系人界面的功能:

  • 自定义Cell

  • 设置分割线

<!--more-->

二 效果图

 

三 功能实现

ContactCell.h

​
#import "Contact.h"
@interface ContactCell : UITableViewCell
@property (nonatomic,strong) Contact *contact;
+(instancetype)cellWithTableView:(UITableView *)tableView;
​
@end

ContactCell.m

#import "ContactCell.h"
#import "Contact.h"
​
@interface ContactCell()
@property (nonatomic,weak) UIView *divide;
@end
​
@implementation ContactCell
​
- (UIView *)divide
{
    if (_divide==nil) {
        UIView *v=[[UIView alloc]init];
        v.backgroundColor=[UIColor blackColor];
        v.alpha=0.2;
        _divide=v;
        [self.contentView addSubview:_divide];
    }
    return _divide;
}
- (void)setContact:(Contact *)contact
{
    _contact=contact;
    //给cell的空间赋值
     self.textLabel.text=contact.name;
     self.detailTextLabel.text=contact.phone;   
}
​
+(instancetype)cellWithTableView:(UITableView *)tableView
{
      static NSString *ID=@"contact";
      return [tableView dequeueReusableCellWithIdentifier:ID];
}
//从XIB加载完成的时候
- (void)awakeFromNib {
    [super awakeFromNib];   
}
-(void)layoutSubviews
{
      [super layoutSubviews];
     //给分割线设置位置
      CGFloat divideH=1;
      CGFloat divideW=self.bounds.size.width;
      CGFloat divideY=self.bounds.size.height-divideH;
      self.divide.frame=CGRectMake(0, divideY, divideW, divideW);
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
​
    // Configure the view for the selected state
}
@end
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值