Notify_SelectCityCell.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // Notify_SelectCityCell.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2017/6/23.
  6. // Copyright © 2017年 lee. All rights reserved.
  7. //
  8. #import "Notify_SelectCityCell.h"
  9. #import "NSString+ex.h"
  10. @interface Notify_SelectCityCell ()
  11. {
  12. UIButton *_isAllBtn;//是否展开
  13. // UIButton *_selectBtn;
  14. }
  15. @end
  16. @implementation Notify_SelectCityCell
  17. +(instancetype)cellForTableView:(UITableView *)tableView{
  18. Notify_SelectCityCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Notify_SelectCityCell"];
  19. if (!cell) {
  20. cell = [[Notify_SelectCityCell alloc] initWithStyle:0 reuseIdentifier:@"Notify_SelectCityCell"];
  21. }
  22. return cell;
  23. }
  24. -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  25. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  26. if (self) {
  27. // UIImage *image1 = [[UIImage imageNamed:@"ic_squSelect_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  28. // UIImage *image2 = [[UIImage imageNamed:@"ic_squSelect"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  29. UIImage *image3 = [[UIImage imageNamed:@"fold"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  30. _isAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  31. [_isAllBtn setImage:image3 forState:UIControlStateSelected];
  32. [_isAllBtn setTitleColor:COLOR_THEME forState:UIControlStateNormal];
  33. [_isAllBtn addTarget:self action:@selector(isAllBtnClick) forControlEvents:UIControlEventTouchUpInside];
  34. [self.contentView addSubview:_isAllBtn];
  35. // _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  36. // [_selectBtn setImage:image1 forState:UIControlStateSelected];
  37. // [_selectBtn setImage:image2 forState:UIControlStateNormal];
  38. // [_selectBtn addTarget:self action:@selector(selectBtnClick) forControlEvents:UIControlEventTouchUpInside];
  39. // _selectBtn.hidden = YES;
  40. // [self.contentView addSubview:_selectBtn];
  41. }
  42. return self;
  43. }
  44. -(void)setTitle:(NSString *)title{
  45. _title = title;
  46. [_isAllBtn setTitle:title forState:UIControlStateNormal];
  47. }
  48. -(void)layoutSubviews{
  49. [super layoutSubviews];
  50. CGFloat x,y,w,h;
  51. // x = kSize.width-70;
  52. // y = 5;
  53. // w = 34;
  54. // h = 34;
  55. // _selectBtn.frame = setDIYFrame;
  56. x = 10;
  57. y = 0;
  58. w = 32+[_isAllBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}].width;
  59. h = 44;
  60. _isAllBtn.frame = setDIYFrame;
  61. //设置对齐方式
  62. _isAllBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  63. _isAllBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
  64. //适应字体及内容,否则titleLabel的尺寸为(0,0)
  65. [_isAllBtn.titleLabel sizeToFit];
  66. CGSize titleSize = _isAllBtn.titleLabel.frame.size;
  67. CGSize buttonSize = _isAllBtn.frame.size;
  68. UIImage *image3 = [[UIImage imageNamed:@"fold"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  69. [_isAllBtn setImageEdgeInsets:UIEdgeInsetsMake((buttonSize.height-image3.size.height)/2, 0, 0, 0)];
  70. [_isAllBtn setTitleEdgeInsets:UIEdgeInsetsMake((buttonSize.height-titleSize.height)/2, 0, 0, 0)];
  71. //
  72. for (UIControl *control in self.subviews) {
  73. if (![control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
  74. continue;
  75. }
  76. for (UIView *subView in control.subviews) {
  77. if (![subView isKindOfClass: [UIImageView class]]) {
  78. continue;
  79. }
  80. //
  81. [subView setValue:[UIColor blackColor] forKey:@"tintColor"];
  82. // UIImageView *imageView = (UIImageView *)subView;
  83. // if (self.selected) {
  84. // imageView.image = [UIImage imageNamed:@"ic_squSelect_h"]; // 选中时的图片
  85. // } else {
  86. // imageView.image = [UIImage imageNamed:@"ic_squSelect"]; // 未选中时的图片
  87. // }
  88. }
  89. }
  90. }
  91. #pragma mark 点击事件
  92. -(void)isAllBtnClick{
  93. if (self.openBlock) {
  94. self.openBlock();
  95. }
  96. }
  97. - (void)updateWithStatus:(BOOL)status {
  98. NSString *name = status ? @"fold" : @"unfold";
  99. UIImage *image = [[UIImage imageNamed:name] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  100. [_isAllBtn setImage:image forState:UIControlStateNormal];
  101. }
  102. //- (void)updateSlcWithStatus:(BOOL)status {
  103. // _selectBtn.selected = status;
  104. //}
  105. //-(void)selectBtnClick{
  106. // _selectBtn.selected = !_selectBtn.selected;
  107. // if (self.selectBlock) {
  108. // self.selectBlock();
  109. // }
  110. //}
  111. //- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
  112. // [super setEditing:editing animated:animated];
  113. // _selectBtn.hidden = !editing;
  114. //}
  115. //- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  116. // [super setSelected:selected animated:animated];
  117. //
  118. // if (self.editing)//仅仅在编辑状态的时候需要自己处理选中效果
  119. // {
  120. // if (selected){
  121. // //选中时的效果
  122. // _selectBtn.selected = YES;
  123. // }
  124. // else {
  125. // //非选中时的效果
  126. // _selectBtn.selected = NO;
  127. // }
  128. // }
  129. //}
  130. - (void)awakeFromNib {
  131. [super awakeFromNib];
  132. // Initialization code
  133. }
  134. @end