设置分割线
// 分割线
@property (nonatomic, strong) UIView *lineView;
// 将分割线添加到cell中
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
[self addSubview:self.lineView];
}
return self;
}
// 设置分割线Frame
- (void)layoutSubviews{
[super layoutSubviews];
CGFloat lineX = self.textLabel.frame.origin.x;
CGFloat lineH = 1;
CGFloat lineY = CGRectGetHeight(self.frame) - 1;
CGFloat lineW = CGRectGetWidth(self.frame) - lineX;
self.lineView.frame = CGRectMake(lineX, lineY, lineW, lineH);
}
// 懒加载分割线
- (UIView *)lineView{
if (_lineView == nil)
{
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [UIColor grayColor];
_lineView.alpha = 0.3;
}
return _lineView;
}