热更新demo

TrackCell.m 6.5KB

    // // TrackCell.m // ThePaperBase // // Created by zhousan on 15/7/30. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "TrackCell.h" #import "loginHomeController.h" @interface TrackCell () { CGFloat contentPadding; } @property (nonatomic, strong) UIImageView *trackIcon; @property (nonatomic, strong) UILabel *contentLabel; @property (nonatomic, strong) UIButton *trackButton; @property (nonatomic, strong) UIView *lineView; @end @implementation TrackCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { if (IS_IPHONE_6P) { contentPadding = 15; }else if (IS_IPHONE_6) { contentPadding = 15; }else { contentPadding = 10; } [self.contentView addSubview:self.trackIcon]; //35x32 [self.contentView addSubview:self.contentLabel]; [self.contentView addSubview:self.trackButton]; [self.contentView addSubview:self.lineView]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; [self setLayoutSubviews]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ [_trackButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal]; [_trackButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK]) forState:UIControlStateSelected]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; _contentLabel.textColor = [UIColor colorWithHexString:TextBlack]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)awakeFromNib { // Initialization code } - (void)setDic:(NSDictionary *)dic { //@"content" //@"isTrack" if (_dic != dic) { _dic = dic; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *str = _dic[@"content"]; // if (!isBlankString(str)) { // if ([str length]>15) { // str = [str substringWithRange:NSMakeRange(0, 14)]; // str = [NSString stringWithFormat:@"%@...",str]; // } // } /** * bug:5094(在新闻详情页中,关键字跟踪,字数允许长度为9,实际可放宽长度) */ dispatch_async(dispatch_get_main_queue(), ^{ self.contentLabel.text = str; self.trackButton.selected = [_dic[@"isTrack"] boolValue]; }); }); } } #pragma mark - getter - (UIImageView *)trackIcon { if (!_trackIcon) { _trackIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _trackIcon.image = Image(@"detailPage/TrackIcon.png"); } return _trackIcon; } - (UIView *)lineView { if (!_lineView) { _lineView = [[UIView alloc] initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _lineView; } - (UIButton *)trackButton { if (!_trackButton) { _trackButton = [UIButton buttonWithType:UIButtonTypeCustom]; _trackButton.frame= CGRectZero; [_trackButton addTarget:self action:@selector(trackButtonClick:) forControlEvents:UIControlEventTouchUpInside]; [_trackButton setImage:Image(@"detailPage/addIcon.png") forState:UIControlStateNormal]; [_trackButton setImage:Image(@"detailPage/ordered.png") forState:UIControlStateSelected]; [_trackButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_trackButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; [_trackButton setTitle:@"跟踪" forState:UIControlStateNormal]; [_trackButton setTitle:@"已跟踪" forState:UIControlStateSelected]; _trackButton.titleLabel.textAlignment = NSTextAlignmentLeft; [_trackButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal]; [_trackButton setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK]) forState:UIControlStateSelected]; } _trackButton.titleLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); return _trackButton; } - (UILabel *)contentLabel { if (!_contentLabel) { _contentLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _contentLabel.textColor = [UIColor colorWithHexString:TextBlack]; _contentLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); } return _contentLabel; } - (void)trackButtonClick:(UIButton *)btn { if ([self.delegate respondsToSelector:@selector(trackButtonClick:)]) { [self.delegate trackButtonClick:btn]; } } - (void)setLayoutSubviews { [self.trackIcon makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(contentPadding); make.top.equalTo(self.contentView.top).offset(11); make.height.mas_equalTo(16); make.width.mas_equalTo(35/2); }]; [self.contentLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.trackIcon.right).offset(25); make.top.equalTo(self.contentView.top).offset(12); make.height.mas_equalTo(16); make.width.mas_equalTo(rect_screen.size.width-2*contentPadding-100); }]; [self.trackButton makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView.top).offset(39/2-10); make.right.equalTo(self.contentView.right).offset(-contentPadding); make.width.mas_equalTo(54); make.height.equalTo(@20); }]; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView.left).offset(contentPadding); make.right.equalTo(self.contentView.right).offset(-contentPadding); make.top.equalTo(self.contentView.top).offset(39); make.height.mas_equalTo(1); }]; self.trackButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 50-5-15/2); [self.trackButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end