OrganizTableViewCell.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // OrganizTableViewCell.m
  3. // shiku_im
  4. //
  5. // Created by 1 on 17/5/12.
  6. // Copyright © 2017年 Reese. All rights reserved.
  7. //
  8. #import "OrganizTableViewCell.h"
  9. //#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  10. @implementation OrganizTableViewCell
  11. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self) {
  14. // self.selectedBackgroundView = [UIView new];
  15. // self.selectedBackgroundView.backgroundColor = [UIColor clearColor];
  16. [self customUI];
  17. }
  18. return self;
  19. }
  20. -(void)layoutSubviews{
  21. [super layoutSubviews];
  22. [self layoutIfNeeded];
  23. _additionButton.frame = CGRectMake(self.frame.size.width -28-6.5, 0, 28, 24);
  24. _additionButton.center = CGPointMake(_additionButton.center.x, self.contentView.center.y);
  25. _nameLabel.center = CGPointMake(_nameLabel.center.x, self.contentView.center.y);
  26. _arrowView.center = CGPointMake(_arrowView.center.x, self.contentView.center.y);
  27. _noticeLab.frame = CGRectMake(CGRectGetMaxX(_nameLabel.frame)+10, 5, JX_SCREEN_WIDTH-CGRectGetMaxX(_nameLabel.frame)-28-6.5-20, 22);
  28. _noticeLab.center = CGPointMake(_noticeLab.center.x, self.contentView.center.y);
  29. }
  30. -(void)customUI{
  31. _arrowView = [[UIImageView alloc] init];
  32. _arrowView.frame = CGRectMake(15, 0, 9, 9);
  33. _arrowView.image = [[UIImage imageNamed:@"arrow_right"] imageWithTintColor:THEMECOLOR];
  34. [self.contentView addSubview:_arrowView];
  35. _nameLabel = [UIFactory createLabelWith:CGRectMake(22, 5, 200, 22) text:@"" font:g_UIFactory.font15 textColor:[UIColor blackColor] backgroundColor:nil];
  36. _nameLabel.textAlignment = NSTextAlignmentLeft;
  37. [self.contentView addSubview:_nameLabel];
  38. _additionButton = [UIButton buttonWithType:UIButtonTypeSystem];
  39. _additionButton.frame = CGRectMake(self.frame.size.width -13-15-6.5, 10, 28, 24);
  40. [self.contentView addSubview:_additionButton];
  41. UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(6.5, 10.5, 13, 3)];
  42. [imgV setImage:[[UIImage imageNamed:@"organize_more"] imageWithTintColor:THEMECOLOR]];
  43. [_additionButton addSubview:imgV];
  44. [_additionButton addTarget:self action:@selector(additionButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
  45. _noticeLab = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_nameLabel.frame), 5, 100, 22)];
  46. _noticeLab.textColor = THEMECOLOR;
  47. _noticeLab.font = SYSFONT(15);
  48. _noticeLab.text = @"暂无公告";
  49. _noticeLab.userInteractionEnabled = YES;
  50. [self.contentView addSubview:_noticeLab];
  51. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onDidNotice:)];
  52. [_noticeLab addGestureRecognizer:tap];
  53. }
  54. - (void)prepareForReuse
  55. {
  56. [super prepareForReuse];
  57. self.arrowExpand = NO;
  58. }
  59. - (void)setupWithData:(DepartObject *)dataObj level:(NSInteger)level expand:(BOOL)expand
  60. {
  61. _arrowView.transform = CGAffineTransformIdentity;
  62. if (expand == YES) {
  63. self.arrowExpand = expand;
  64. }
  65. self.nameLabel.text = dataObj.departName;
  66. self.organizObject = dataObj;
  67. // if (level == 0) {
  68. // self.backgroundColor = HEXCOLOR(0xe3e6e8);
  69. // self.nameLabel.textColor = [UIColor blackColor];
  70. // }else{
  71. // self.backgroundColor = [UIColor whiteColor];
  72. // self.nameLabel.textColor = [UIColor grayColor];
  73. // }
  74. CGFloat left = 15 * (level+1);
  75. CGRect arrowFrame = self.arrowView.frame;
  76. arrowFrame.origin.x = left;
  77. self.arrowView.frame = arrowFrame;
  78. CGSize size = [self.nameLabel.text sizeWithAttributes:@{NSFontAttributeName:SYSFONT(15)}];
  79. CGRect titleFrame = self.nameLabel.frame;
  80. titleFrame.origin.x = left +22;
  81. titleFrame.size.width = size.width;
  82. self.nameLabel.frame = titleFrame;
  83. _noticeLab.hidden = level != 0;
  84. if (!IsStringNull(dataObj.noticeContent)) {
  85. self.noticeLab.text = dataObj.noticeContent;
  86. }
  87. }
  88. #pragma mark - Properties
  89. -(void)setArrowExpand:(BOOL)arrowExpand{
  90. [self setArrowExpand:arrowExpand animated:YES];
  91. }
  92. - (void)setArrowExpand:(BOOL)arrowExpand animated:(BOOL)animated{
  93. _arrowExpand = arrowExpand;
  94. [UIView animateWithDuration:animated ? 0.2 : 0 animations:^{
  95. if (arrowExpand) {
  96. _arrowView.transform = CGAffineTransformRotate(_arrowView.transform, M_PI_2);
  97. }else{
  98. _arrowView.transform = CGAffineTransformRotate(_arrowView.transform, -M_PI_2);
  99. }
  100. // _arrowView.hidden = arrowExpand;
  101. }];
  102. }
  103. //- (void)setAdditionButtonHidden:(BOOL)additionButtonHidden
  104. //{
  105. // [self setAdditionButtonHidden:additionButtonHidden animated:NO];
  106. //}
  107. //- (void)setAdditionButtonHidden:(BOOL)additionButtonHidden animated:(BOOL)animated
  108. //{
  109. // _additionButtonHidden = additionButtonHidden;
  110. // [UIView animateWithDuration:animated ? 0.2 : 0 animations:^{
  111. // self.additionButton.hidden = additionButtonHidden;
  112. // }];
  113. //}
  114. #pragma mark - Actions
  115. - (void)additionButtonTapped:(id)sender
  116. {
  117. if (self.additionButtonTapAction) {
  118. self.additionButtonTapAction(sender);
  119. }
  120. }
  121. - (void)onDidNotice:(UITapGestureRecognizer *)tap {
  122. if (self.noticeLabTapAction) {
  123. self.noticeLabTapAction(self.organizObject);
  124. }
  125. }
  126. @end