123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // Notify_SelectCityCell.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/6/23.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "Notify_SelectCityCell.h"
- #import "NSString+ex.h"
- @interface Notify_SelectCityCell ()
- {
- UIButton *_isAllBtn;//是否展开
- // UIButton *_selectBtn;
- }
- @end
- @implementation Notify_SelectCityCell
- +(instancetype)cellForTableView:(UITableView *)tableView{
-
- Notify_SelectCityCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Notify_SelectCityCell"];
- if (!cell) {
- cell = [[Notify_SelectCityCell alloc] initWithStyle:0 reuseIdentifier:@"Notify_SelectCityCell"];
- }
- return cell;
- }
- -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
-
- self = [super initWithStyle:style reuseIdentifier: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:COLOR_THEME forState:UIControlStateNormal];
- [_isAllBtn addTarget:self action:@selector(isAllBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.contentView 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.contentView addSubview:_selectBtn];
- }
- return self;
- }
- -(void)setTitle:(NSString *)title{
- _title = title;
- [_isAllBtn setTitle:title forState:UIControlStateNormal];
- }
- -(void)layoutSubviews{
-
- [super layoutSubviews];
-
- CGFloat x,y,w,h;
- // x = kSize.width-70;
- // y = 5;
- // w = 34;
- // h = 34;
- // _selectBtn.frame = setDIYFrame;
-
- x = 10;
- y = 0;
- w = 32+[_isAllBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]}].width;
- h = 44;
- _isAllBtn.frame = setDIYFrame;
-
- //设置对齐方式
- _isAllBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _isAllBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
- //适应字体及内容,否则titleLabel的尺寸为(0,0)
- [_isAllBtn.titleLabel sizeToFit];
- CGSize titleSize = _isAllBtn.titleLabel.frame.size;
- CGSize buttonSize = _isAllBtn.frame.size;
- UIImage *image3 = [[UIImage imageNamed:@"fold"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- [_isAllBtn setImageEdgeInsets:UIEdgeInsetsMake((buttonSize.height-image3.size.height)/2, 0, 0, 0)];
- [_isAllBtn setTitleEdgeInsets:UIEdgeInsetsMake((buttonSize.height-titleSize.height)/2, 0, 0, 0)];
-
- //
- for (UIControl *control in self.subviews) {
- if (![control isMemberOfClass:NSClassFromString(@"UITableViewCellEditControl")]){
- continue;
- }
-
- for (UIView *subView in control.subviews) {
- if (![subView isKindOfClass: [UIImageView class]]) {
- continue;
- }
-
- //
- [subView setValue:[UIColor blackColor] forKey:@"tintColor"];
-
- // UIImageView *imageView = (UIImageView *)subView;
- // if (self.selected) {
- // imageView.image = [UIImage imageNamed:@"ic_squSelect_h"]; // 选中时的图片
- // } else {
- // imageView.image = [UIImage imageNamed:@"ic_squSelect"]; // 未选中时的图片
- // }
- }
- }
- }
- #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)updateSlcWithStatus:(BOOL)status {
- // _selectBtn.selected = status;
- //}
- //-(void)selectBtnClick{
- // _selectBtn.selected = !_selectBtn.selected;
- // if (self.selectBlock) {
- // self.selectBlock();
- // }
- //}
- //- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
- // [super setEditing:editing animated:animated];
- // _selectBtn.hidden = !editing;
- //}
- //- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- // [super setSelected:selected animated:animated];
- //
- // if (self.editing)//仅仅在编辑状态的时候需要自己处理选中效果
- // {
- // if (selected){
- // //选中时的效果
- // _selectBtn.selected = YES;
- // }
- // else {
- // //非选中时的效果
- // _selectBtn.selected = NO;
- // }
- // }
- //}
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- @end
|