|
//
// liveContFootCell.m
// ThePaperHD
//
// Created by scar1900 on 15/3/11.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "liveContFootCell.h"
#define CONTENTWIDTH rect_screen.size.width
@interface liveContFootCell()
@property(nonatomic, strong)UIButton *askMoreBtn;
@property(nonatomic, strong)UIView *bottomLine;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UILabel *shareLabel;
@property(nonatomic, strong)UIButton *shareBtn;
@end
@implementation liveContFootCell
@synthesize dataDic = _dataDic;
@synthesize delegate;
@synthesize indexPath;
@synthesize isLast;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self addSubview:self.askMoreBtn];
[self addSubview:self.bottomLine];
[self addSubview:self.lineView];
[self addSubview:self.shareBtn];
[self.shareBtn addSubview:self.shareLabel];
self.isLast = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
_shareLabel.textColor = [UIColor colorWithHexString:TextGray];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[_askMoreBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal];
[_askMoreBtn setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
_bottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)setDataDic:(NSDictionary *)dic {
_dataDic = dic;
if ([dic.allKeys containsObject:@"strongRelate"]) {
[self.askMoreBtn setHidden:NO];
}else {
[self.askMoreBtn setHidden:YES];
}
NSString *type = dic[@"type"];
if ([type isMatchedByRegex:@"top"]) {
self.lineView.hidden = YES;
}else self.lineView.hidden = NO;
[self layoutSubViews];
}
- (UIButton*)askMoreBtn {
if (!_askMoreBtn) {
_askMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_askMoreBtn setTitle:@"点击查看详情" forState:UIControlStateNormal];
[_askMoreBtn setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal];
[_askMoreBtn setTitleColor:[UIColor colorWithHexString:BUTTONSELECTBACK] forState:UIControlStateHighlighted];
_askMoreBtn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_askMoreBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
[_askMoreBtn addTarget:self action:@selector(askMoreHanlder:) forControlEvents:UIControlEventTouchUpInside];
}
return _askMoreBtn;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (UIView*)bottomLine {
if (!_bottomLine) {
_bottomLine = [[UIView alloc]initWithFrame:CGRectZero];
_bottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _bottomLine;
}
- (UILabel*)shareLabel {
if (!_shareLabel) {
_shareLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_shareLabel.text = @"分享";
_shareLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
_shareLabel.textColor = [UIColor colorWithHexString:TextGray];
_shareLabel.textAlignment = NSTextAlignmentCenter;
_shareLabel.backgroundColor = [UIColor clearColor];
}
return _shareLabel;
}
- (UIButton*)shareBtn {
if (!_shareBtn) {
_shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_shareBtn setImage:Image(@"imageList/shareBtn.png") forState:UIControlStateNormal];
[_shareBtn addTarget:self action:@selector(shareHandler:) forControlEvents:UIControlEventTouchUpInside];
_shareBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 40);
}
return _shareBtn;
}
- (void)askMoreHanlder:(UIButton*)btn {
if ([self.delegate respondsToSelector:@selector(goToDetailPage:)]) {
[self.delegate goToDetailPage:self.dataDic[@"strongRelate"]];
}
}
- (void)shareHandler:(UIButton*)btn {
NSString* shareText = self.dataDic[@"title"];
if ([self.delegate respondsToSelector:@selector(shareEvent:button:)]) {
[self.delegate shareEvent:shareText button:btn];
}
}
- (void)layoutSubViews {
CGFloat width = widthForString(self.askMoreBtn.titleLabel.text, self.askMoreBtn.titleLabel.font, 17, NSLineBreakByCharWrapping);
[self.askMoreBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.left).offset(50);
make.width.mas_equalTo(width);
make.top.mas_equalTo(self.top);
make.height.mas_equalTo(16);
}];
[self.shareBtn makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.right).offset(-5);
make.width.mas_equalTo(60);
make.top.mas_equalTo(self.askMoreBtn.top);
make.height.mas_equalTo(20);
}];
[self.shareLabel remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.shareBtn.right).offset(-3);
make.top.mas_equalTo(self.shareBtn.top).offset(2);
make.width.mas_equalTo(30);
make.height.mas_equalTo(16);
}];
[self.bottomLine makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.left).offset(50);
make.right.mas_equalTo(self.right).offset(-10);
make.top.mas_equalTo(self.top).offset(33);
make.height.mas_equalTo(1);
}];
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|