// // Notify_SelectCityHeaderView.m // LNManager // // Created by EchoShacolee on 2017/6/22. // Copyright © 2017年 lee. All rights reserved. // #import "Notify_SelectCityHeaderView.h" @interface Notify_SelectCityHeaderView () { UIButton *_isAllBtn;//是否展开 UIButton *_selectBtn; } @end @implementation Notify_SelectCityHeaderView +(instancetype)cellHeaderViewForTableView:(UITableView *)tableView{ Notify_SelectCityHeaderView * headerV = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"Notify_SelectCityHeaderView"]; if (!headerV) { headerV = [[Notify_SelectCityHeaderView alloc] initWithReuseIdentifier:@"Notify_SelectCityHeaderView"]; NSLog(@"创建了headerView"); } return headerV; } -(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithReuseIdentifier:reuseIdentifier]; if (self) { UIImage *image1 = [[UIImage imageNamed:@"ic_squSelect_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; UIImage *image2 = [[UIImage imageNamed:@"ic_squSelect"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; UIImage *image3 = [[UIImage imageNamed:@"fold"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];; _isAllBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_isAllBtn setImage:image3 forState:UIControlStateSelected]; [_isAllBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal]; _isAllBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [_isAllBtn addTarget:self action:@selector(isAllBtnClick) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:_isAllBtn]; _selectBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_selectBtn setImage:image1 forState:UIControlStateSelected]; [_selectBtn setImage:image2 forState:UIControlStateNormal]; [_selectBtn addTarget:self action:@selector(selectBtnClick) forControlEvents:UIControlEventTouchUpInside]; _selectBtn.hidden = YES; [self addSubview:_selectBtn]; } return self; } -(void)setTitle:(NSString *)title{ _title = title; [_isAllBtn setTitle:title forState:UIControlStateNormal]; } -(void)layoutSubviews{ CGFloat x,y,w,h; x = kSize.width-70; y = 5; w = 34; h = 34; _selectBtn.frame = setDIYFrame; x = 10; y = 0; w = kSize.width - 70; h = 44; _isAllBtn.frame = setDIYFrame; } #pragma mark 点击事件 -(void)isAllBtnClick{ if (self.openBlock) { self.openBlock(); } } - (void)updateWithStatus:(BOOL)status { NSString *name = status ? @"fold" : @"unfold"; UIImage *image = [[UIImage imageNamed:name] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [_isAllBtn setImage:image forState:UIControlStateNormal]; } -(void)selectBtnClick{ _selectBtn.selected = !_selectBtn.selected; if (self.selectBlock) { self.selectBlock(); } } #pragma mark 响应属性值变化后的方法 -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ if ([keyPath isEqualToString:@"editing"]) { NSString *str = [NSString stringWithFormat:@"%@",change[@"new"]]; BOOL isEditing = [str boolValue]; NSLog(@"%u",isEditing); _selectBtn.hidden = !isEditing; } } @end