HEMenuTableCell.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // HEMenuTableCell.m
  3. // YHMenu
  4. //
  5. // Created by Boris on 2018/5/27.
  6. //
  7. //
  8. #import "HEMenuTableCell.h"
  9. #import "UIColor+Hex.h"
  10. #define kLineXY 15.f // 距离
  11. #define kImgWidth 20.f // 图片宽
  12. #define kImgLabelWidth 10.f // 图片和Label宽
  13. @implementation HEMenuTableCell
  14. - (UIView *)lineView
  15. {
  16. if (!_lineView) {
  17. self.lineView = ({
  18. UIView *lineView = [UIView new];
  19. lineView.backgroundColor = [UIColor colorWithHexString:@"#e4e4e4"];
  20. lineView.frame = CGRectMake(kLineXY, 0, _width - kLineXY * 2, 1);
  21. lineView;
  22. });
  23. }
  24. return _lineView;
  25. }
  26. - (UIImageView *)iconImg
  27. {
  28. if (!_iconImg) {
  29. self.iconImg = ({
  30. UIImageView *imageView = [UIImageView new];
  31. imageView.backgroundColor = [UIColor clearColor];
  32. imageView.frame = CGRectMake(kLineXY, (_height-kImgWidth)/2, kImgWidth, kImgWidth);
  33. imageView;
  34. });
  35. }
  36. return _iconImg;
  37. }
  38. - (UILabel *)conLabel
  39. {
  40. if (!_conLabel) {
  41. self.conLabel = ({
  42. UILabel *label = [UILabel new];
  43. label.textColor = [UIColor colorWithHexString:@"#333333"];
  44. label.font = [UIFont systemFontOfSize:14];
  45. label.frame = CGRectMake(CGRectGetMaxX(self.iconImg.frame) + kImgLabelWidth, 0, _width - kImgLabelWidth - kLineXY - kImgWidth - 15, _height);
  46. label;
  47. });
  48. }
  49. return _conLabel;
  50. }
  51. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier width:(CGFloat)width height:(CGFloat)height
  52. {
  53. if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  54. _width = width;
  55. _height = height;
  56. [self.contentView addSubview:self.lineView];
  57. [self.contentView addSubview:self.iconImg];
  58. [self.contentView addSubview:self.conLabel];
  59. }
  60. return self;
  61. }
  62. - (void)setContentByTitArray:(NSMutableArray *)titArray ImgArray:(NSMutableArray *)imgArray row:(NSInteger)row
  63. {
  64. if (imgArray.count == 0) {
  65. _iconImg.hidden = YES;
  66. self.conLabel.frame = CGRectMake(kLineXY, 0, _width - kLineXY*2 , _height);
  67. _conLabel.textAlignment = NSTextAlignmentCenter;
  68. }else{
  69. _iconImg.hidden = NO;
  70. self.conLabel.frame = CGRectMake(CGRectGetMaxX(self.iconImg.frame) + kImgLabelWidth, 0, _width - kImgLabelWidth - kLineXY - kImgWidth - 15, _height);
  71. _iconImg.image = [UIImage imageNamed:imgArray[row]];
  72. _conLabel.text = titArray[row];
  73. }
  74. }
  75. @end