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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章