123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // 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
|