UITableViewCell+XL.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // XLTableViewCell+XL.m
  3. // amigo
  4. //
  5. // Created by wujian on 2017/8/29.
  6. // Copyright © 2017年 xiaolian.Inc. All rights reserved.
  7. //
  8. #import "UITableViewCell+XL.h"
  9. #import "Masonry.h"
  10. static int const XLCellHeaderLineTag = 80000;
  11. static int const XLCellFooterLineTag = 90000;
  12. @implementation UITableViewCell (XL)
  13. - (void)addHeaderLineWithColor:(UIColor *)tColor lineX:(float)tx
  14. {
  15. UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag];
  16. if (headerLineView == nil) {
  17. headerLineView = [[UIView alloc] init];
  18. headerLineView.tag = XLCellHeaderLineTag;
  19. [self.contentView addSubview:headerLineView];
  20. }
  21. [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.leading.equalTo(self.contentView).offset(tx);
  23. make.top.equalTo(self.contentView);
  24. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight));
  25. }];
  26. headerLineView.backgroundColor = tColor;
  27. }
  28. - (void)addHeaderLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx
  29. {
  30. [self addHeaderLineWithColor:tColor leadingeX:lx trailingX:tx lineHeight:HalfPxHeight];
  31. }
  32. - (void)addHeaderLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx lineHeight:(float)lh;
  33. {
  34. UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag];
  35. if (headerLineView == nil) {
  36. headerLineView = [[UIView alloc] init];
  37. headerLineView.tag = XLCellHeaderLineTag;
  38. [self.contentView addSubview:headerLineView];
  39. }
  40. [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.leading.equalTo(self.contentView).offset(lx);
  42. make.top.equalTo(self.contentView);
  43. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - lx - tx, lh));
  44. }];
  45. headerLineView.backgroundColor = tColor;
  46. }
  47. - (void)addHeaderLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht
  48. {
  49. UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag];
  50. if (headerLineView == nil) {
  51. headerLineView = [[UIView alloc] init];
  52. headerLineView.tag = XLCellHeaderLineTag;
  53. [self.contentView addSubview:headerLineView];
  54. }
  55. [headerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.leading.equalTo(self.contentView).offset(tx);
  57. make.top.equalTo(self.contentView);
  58. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight));
  59. }];
  60. headerLineView.backgroundColor = tColor;
  61. }
  62. - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx
  63. {
  64. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  65. if (footerLineView == nil) {
  66. footerLineView = [[UIView alloc] init];
  67. footerLineView.tag = XLCellFooterLineTag;
  68. [self.contentView addSubview:footerLineView];
  69. }
  70. [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.leading.equalTo(self.contentView).offset(tx);
  72. make.bottom.equalTo(self.contentView);
  73. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight));
  74. }];
  75. footerLineView.backgroundColor = tColor;
  76. }
  77. - (void)addfooterLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx
  78. {
  79. [self addfooterLineWithColor:tColor leadingeX:lx trailingX:tx lineHeight:HalfPxHeight];
  80. }
  81. - (void)addfooterLineWithColor:(UIColor *)tColor leadingeX:(float)lx trailingX:(float)tx lineHeight:(float)lh
  82. {
  83. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  84. if (footerLineView == nil) {
  85. footerLineView = [[UIView alloc] init];
  86. footerLineView.tag = XLCellFooterLineTag;
  87. [self.contentView addSubview:footerLineView];
  88. }
  89. [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.leading.equalTo(self.contentView).offset(lx);
  91. make.bottom.equalTo(self.contentView);
  92. make.trailing.equalTo(self.contentView).offset(-tx);
  93. make.height.mas_equalTo(lh);
  94. }];
  95. footerLineView.backgroundColor = tColor;
  96. }
  97. - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht
  98. {
  99. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  100. if (footerLineView == nil) {
  101. footerLineView = [[UIView alloc] init];
  102. footerLineView.tag = XLCellFooterLineTag;
  103. [self.contentView addSubview:footerLineView];
  104. }
  105. [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.leading.equalTo(self.contentView).offset(tx);
  107. make.bottom.equalTo(self.contentView);
  108. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, HalfPxHeight));
  109. }];
  110. footerLineView.backgroundColor = tColor;
  111. }
  112. - (void)addfooterLineWithColor:(UIColor *)tColor lineX:(float)tx cellHeight:(float)ht lineHeight:(float)lx
  113. {
  114. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  115. if (footerLineView == nil) {
  116. footerLineView = [[UIView alloc] init];
  117. footerLineView.tag = XLCellFooterLineTag;
  118. [self.contentView addSubview:footerLineView];
  119. }
  120. [footerLineView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.leading.equalTo(self.contentView).offset(tx);
  122. make.bottom.equalTo(self.contentView);
  123. make.size.mas_equalTo(CGSizeMake(kGXScreenWidth - tx, lx));
  124. }];
  125. footerLineView.backgroundColor = tColor;
  126. }
  127. - (void)addLinesOnHeaderAndFooterWithColor:(UIColor *)tColor
  128. {
  129. [self addHeaderLineWithColor:tColor lineX:0.0f];
  130. [self addfooterLineWithColor:tColor lineX:0.0f];
  131. }
  132. - (void)cleanLinesOnHeaderAndFooter
  133. {
  134. UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag];
  135. [headerLineView removeFromSuperview];
  136. headerLineView = nil;
  137. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  138. [footerLineView removeFromSuperview];
  139. footerLineView = nil;
  140. }
  141. - (void)setHeaderLineHiden:(BOOL)isHiden
  142. {
  143. UIView *headerLineView = [self.contentView viewWithTag:XLCellHeaderLineTag];
  144. if (nil != headerLineView) {
  145. headerLineView.hidden = isHiden;
  146. }
  147. }
  148. - (void)setFooterLineHiden:(BOOL)isHiden
  149. {
  150. UIView *footerLineView = [self.contentView viewWithTag:XLCellFooterLineTag];
  151. if (nil != footerLineView) {
  152. footerLineView.hidden = isHiden;
  153. }
  154. }
  155. #pragma mark background view
  156. - (void)setNormalBackgroundViewWithColor:(UIColor *)tColor
  157. {
  158. UIView *norBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, self.frame.size.height)];
  159. norBgView.backgroundColor = tColor;
  160. self.backgroundView = norBgView;
  161. }
  162. - (void)setSelectedBackgroundViewWithColor:(UIColor *)tColor
  163. {
  164. UIView *selBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kGXScreenWidth, self.frame.size.height)];
  165. selBgView.backgroundColor = tColor;
  166. self.selectedBackgroundView = selBgView;
  167. }
  168. @end