1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #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
|