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 53 54 55 56 57 58 59 60
| @interface ZDBaseTableViewCell ()
@property (nonatomic, strong) CALayer *separatorLayer;
@end
@implementation ZDBaseTableViewCell
- (void)awakeFromNib { [super awakeFromNib]; }
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self setup]; } return self; }
- (instancetype)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { [self setup]; } return self; }
- (void)setup { _separatorLeading = 15.f; _showsSeparator = YES;
_separatorLayer = [[CALayer alloc] init]; _separatorLayer.backgroundColor = [UIColor zd_separatorColor].CGColor; [self.layer addSublayer:_separatorLayer]; }
- (void)setShowsSeparator:(BOOL)showsSeparator { _showsSeparator = showsSeparator; _separatorLayer.hidden = !showsSeparator; }
- (void)layoutSubviews { [super layoutSubviews]; if (_showsSeparator) { [UIView setAnimationsEnabled:NO]; self.separatorLayer.frame = CGRectMake(_separatorLeading, CGRectGetHeight(self.bounds) - SINGLE_LINE_ADJUST_OFFSET, CGRectGetWidth(self.bounds) - _separatorLeading, SINGLE_LINE_HEIGHT); [UIView setAnimationsEnabled:YES]; } }
@end
|