// // XLTableViewCell+XL.m // amigo // // Created by wujian on 2017/8/29. // Copyright © 2017年 xiaolian.Inc. All rights reserved. // #import "UITableViewCell+XL.h" #import "Masonry.h" static int const XLCellHeaderLineTag = 80000; static int const XLCellFooterLineTag = 90000; @implementation UITableViewCell (XL) - (void)addHeaderLineWithColor:(UIColor *)tColor lineX:(float)tx { UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag]; if (headerLineView == nil) { headerLineView = [[UIView alloc] init]; headerLineView.tag = XLCellHeaderLineTag; [self.contentView addSubview:headerLineView]; } [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(tx); make.top.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight)); }]; headerLineView.backgroundColor = tColor; } - (void)addHeaderLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx { [self addHeaderLineWithColor:tColor leadingeX:lx trailingX:tx lineHeight:HalfPxHeight]; } - (void)addHeaderLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx lineHeight:(float)lh; { UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag]; if (headerLineView == nil) { headerLineView = [[UIView alloc] init]; headerLineView.tag = XLCellHeaderLineTag; [self.contentView addSubview:headerLineView]; } [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(lx); make.top.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - lx - tx, lh)); }]; headerLineView.backgroundColor = tColor; } - (void)addHeaderLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht { UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag]; if (headerLineView == nil) { headerLineView = [[UIView alloc] init]; headerLineView.tag = XLCellHeaderLineTag; [self.contentView addSubview:headerLineView]; } [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(tx); make.top.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight)); }]; headerLineView.backgroundColor = tColor; } - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx { UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; if (footerLineView == nil) { footerLineView = [[UIView alloc] init]; footerLineView.tag = XLCellFooterLineTag; [self.contentView addSubview:footerLineView]; } [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(tx); make.bottom.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight)); }]; footerLineView.backgroundColor = tColor; } - (void)addfooterLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx { [self addfooterLineWithColor:tColor leadingeX:lx trailingX:tx lineHeight:HalfPxHeight]; } - (void)addfooterLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx lineHeight:(float)lh { UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; if (footerLineView == nil) { footerLineView = [[UIView alloc] init]; footerLineView.tag = XLCellFooterLineTag; [self.contentView addSubview:footerLineView]; } [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(lx); make.bottom.equalTo(self.contentView); make.trailing.equalTo(self.contentView).offset(-tx); make.height.mas_equalTo(lh); }]; footerLineView.backgroundColor = tColor; } - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht { UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; if (footerLineView == nil) { footerLineView = [[UIView alloc] init]; footerLineView.tag = XLCellFooterLineTag; [self.contentView addSubview:footerLineView]; } [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(tx); make.bottom.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight)); }]; footerLineView.backgroundColor = tColor; } - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht lineHeight:(float)lx { UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; if (footerLineView == nil) { footerLineView = [[UIView alloc] init]; footerLineView.tag = XLCellFooterLineTag; [self.contentView addSubview:footerLineView]; } [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) { make.leading.equalTo(self.contentView).offset(tx); make.bottom.equalTo(self.contentView); make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, lx)); }]; footerLineView.backgroundColor = tColor; } - (void)addLinesOnHeaderAndFooterWithColor:(UIColor *)tColor { [self addHeaderLineWithColor:tColor lineX:0.0f]; [self addfooterLineWithColor:tColor lineX:0.0f]; } - (void)cleanLinesOnHeaderAndFooter { UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag]; [headerLineView removeFromSuperview]; headerLineView = nil; UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; [footerLineView removeFromSuperview]; footerLineView = nil; } - (void)setHeaderLineHiden:(BOOL)isHiden { UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag]; if (nil != headerLineView) { headerLineView.hidden = isHiden; } } - (void)setFooterLineHiden:(BOOL)isHiden { UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag]; if (nil != footerLineView) { footerLineView.hidden = isHiden; } } #pragma mark background view - (void)setNormalBackgroundViewWithColor:(UIColor *)tColor { UIView *norBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, self.frame.size.height)]; norBgView.backgroundColor = tColor; self.backgroundView = norBgView; } - (void)setSelectedBackgroundViewWithColor:(UIColor *)tColor { UIView *selBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, self.frame.size.height)]; selBgView.backgroundColor = tColor; self.selectedBackgroundView = selBgView; } @end