// // nodeInfoCell.m // ThePaperDemo // // Created by scar1900 on 14-9-30. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "nodeInfoCell.h" #import "AsyncImageView.h" @interface nodeInfoCell() @property(nonatomic, strong)AsyncImageView *nodeImageView; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UIButton *deleteButton; @end @implementation nodeInfoCell @synthesize nodeInfoBO = _nodeInfoBO; @synthesize isDelete = _isDelete; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; // UIView *cellHLineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds)-1, CGRectGetWidth(self.bounds), 1)]; // cellHLineView.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR]; // [self addSubview:cellHLineView]; // // UIView *cellVLineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)-1,0, 1, CGRectGetHeight(self.bounds))]; // cellVLineView.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR]; // [self addSubview:cellVLineView]; self.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; self.layer.borderWidth = 0.5; [self addSubview:self.nodeImageView]; [self addSubview:self.titleLabel]; [self addSubview:self.deleteButton]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshAfterOpenNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)setNodeInfoBO:(nodeObjectBO *)data { _nodeInfoBO = data; self.nodeImageView.imageUrl = data.pic; self.nodeImageView.imageId = getImageNameFromURL(data.pic); self.nodeImageView.imageView.backgroundColor = [UIColor clearColor]; /** * bug:5346(频道导航页,每个栏目的logo均有灰色的底色,而网达版本没有) */ self.titleLabel.text = data.name?data.name:@""; } - (AsyncImageView*)nodeImageView { if (!_nodeImageView) { _nodeImageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)/2-35/2, CGRectGetHeight(self.bounds)/2-35/2, 35, 35)]; _nodeImageView.isHaveWaterPrint = NO; _nodeImageView.backColor = [UIColor colorWithHexString:BLUECOLOR]; /** * bug:5287(打底图问题汇总) */ } return _nodeImageView; } - (UILabel*)titleLabel { if (!_titleLabel) { CGFloat offset = 15; if (IS_IPHONE_6P) { offset = 16; } _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.nodeImageView.frame) + offset, CGRectGetWidth(self.bounds), 15)]; _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textAlignment = NSTextAlignmentCenter; } _titleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO); _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; return _titleLabel; } - (UIButton*)deleteButton { if (!_deleteButton) { _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; _deleteButton.frame = CGRectMake(CGRectGetWidth(self.bounds)-41/2-5/2, 5/2, 41/2, 41/2); [_deleteButton setImage:Image(@"Button/delete.png") forState:UIControlStateNormal]; [_deleteButton setImage:Image(@"Button/delete_s.png") forState:UIControlStateHighlighted]; _deleteButton.hidden = YES; [_deleteButton addTarget:self action:@selector(cancelOrder:) forControlEvents:UIControlEventTouchUpInside]; } return _deleteButton; } - (void)setIsDelete:(BOOL)delete { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; if (_isDelete == delete) { return; } _isDelete = delete; if (delete) { self.deleteButton.transform = CGAffineTransformMakeScale(0.0, 0.0); [UIView animateWithDuration:0.3 animations:^{ self.deleteButton.transform = CGAffineTransformMakeScale(1.0, 1.0); self.deleteButton.hidden = NO; }]; }else { [UIView animateWithDuration:0.3 animations:^{ self.deleteButton.transform = CGAffineTransformMakeScale(0.0, 0.0); self.deleteButton.hidden = YES; }]; } } - (void)setSelected:(BOOL)selected { [super setSelected:YES]; if (selected) { self.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR]; }else { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } } - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted) { self.backgroundColor = [UIColor colorWithHexString:GRAYCOLOR]; }else { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } } - (void)cancelOrder:(UIButton*)btn { NSDictionary *dic = @{@"n":self.nodeInfoBO.nodeId,@"oType":@"2"}; [Remote doJsonAction:1 requestUrl:orderNodeURL parameter:dic delegate:self]; } - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (responsData && [responsData[@"resultCode"] intValue] == 1) { if (cancelOrderBlock) { cancelOrderBlock(self.nodeInfoBO); } } } - (void)cancelOrderBlock:(void (^)(nodeObjectBO *))block { cancelOrderBlock = [block copy]; } - (void)layoutSubviews { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor; self.layer.borderWidth = 0.5; self.titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; /** * bug:5349(夜间模式,栏目页的文字颜色显示错误) */ if (IS_IPHONE_6P) { CGFloat offset = 160/3; [self.nodeImageView remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(offset); make.top.equalTo(self.top).offset(offset); make.right.equalTo(self.right).offset(-offset); make.bottom.equalTo(self.bottom).offset(-offset); }]; }else if (IS_IPHONE_6) { CGFloat offset = 81-35; [self.nodeImageView remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(offset); make.top.equalTo(self.top).offset(offset); make.right.equalTo(self.right).offset(-offset); make.bottom.equalTo(self.bottom).offset(-offset); }]; } [super layoutSubviews]; } - (void)refreshAfterOpenNightMode:(NSNotification*)noti { [self layoutSubviews]; } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } @end