|
//
// recommendCell.m
// ThePaperBase
//
// Created by Huixin on 15/10/26.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "recommendCell.h"
#import "shareUtil.h"
@interface recommendCell()
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *seashellLabel;
@property(nonatomic, strong)UIButton *wechatBtn;
@property(nonatomic, strong)UIButton *friendBtn;
@property(nonatomic, strong)UIButton *weiboBtn;
@property(nonatomic, strong)UIButton *QQZoneBtn;
@property(nonatomic, strong)UIButton *QQBtn;
@property(nonatomic, strong)UIView *line;
@end
@implementation recommendCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.clipsToBounds = YES;
[self addSubview:self.titleLabel];
[self addSubview:self.seashellLabel];
[self addSubview:self.wechatBtn];
[self addSubview:self.friendBtn];
[self addSubview:self.weiboBtn];
[self addSubview:self.QQZoneBtn];
[self addSubview:self.QQBtn];
[self layoutViews];
}
return self;
}
- (void)layoutViews {
[self.titleLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.top).offset(20);
make.left.equalTo(self.left).offset(10);
make.height.mas_equalTo(@17);
make.width.mas_equalTo(rect_screen.size.width*0.7);
}];
[self.seashellLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.right);
make.right.equalTo(self.right).offset(-10);
make.bottom.equalTo(self.titleLabel.bottom);
make.height.mas_equalTo(@15);
}];
CGFloat btnWidth = rect_screen.size.width*0.125;
CGFloat padding = (rect_screen.size.width-20-btnWidth*5)/4;
[self.wechatBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.bottom.equalTo(self.bottom).offset(-10);
make.width.mas_equalTo(btnWidth);
make.height.mas_equalTo(btnWidth);
}];
[self.friendBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatBtn.top);
make.left.equalTo(self.wechatBtn.right).offset(padding);
make.width.and.height.mas_equalTo(btnWidth);
}];
[self.weiboBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatBtn.top);
make.left.equalTo(self.friendBtn.right).offset(padding);
make.width.and.height.mas_equalTo(btnWidth);
}];
[self.QQZoneBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatBtn.top);
make.left.equalTo(self.weiboBtn.right).offset(padding);
make.width.and.height.mas_equalTo(btnWidth);
}];
[self.QQBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.wechatBtn.top);
make.left.equalTo(self.QQZoneBtn.right).offset(padding);
make.width.and.height.mas_equalTo(btnWidth);
}];
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
}
return _titleLabel;
}
- (UILabel*)seashellLabel {
if (!_seashellLabel) {
_seashellLabel = [UILabel new];
_seashellLabel.backgroundColor = [UIColor clearColor];
_seashellLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_seashellLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_seashellLabel.textAlignment = NSTextAlignmentRight;
}
return _seashellLabel;
}
- (UIButton*)wechatBtn {
if (!_wechatBtn) {
_wechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_wechatBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b24d"])
forState:UIControlStateNormal];
[_wechatBtn addTarget:self action:@selector(wechatRecommend) forControlEvents:UIControlEventTouchUpInside];
if (![shareUtil isHaveWeChatClient]) {
_wechatBtn.enabled = NO;
}else {
_wechatBtn.enabled = YES;
}
[self setButtonHiligthAndDisableColor:_wechatBtn];
_wechatBtn.layer.cornerRadius = 2.f;
_wechatBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"mall/recommendWechat.png");
CGSize size = btnImageView.image.size;
[_wechatBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_wechatBtn.center);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _wechatBtn;
}
- (UIButton*)friendBtn {
if (!_friendBtn) {
_friendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_friendBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b24d"])
forState:UIControlStateNormal];
[_friendBtn addTarget:self action:@selector(friendRecommend) forControlEvents:UIControlEventTouchUpInside];
if (![shareUtil isHaveWeChatClient]) {
_friendBtn.enabled = NO;
}else {
_friendBtn.enabled = YES;
}
[self setButtonHiligthAndDisableColor:_friendBtn];
_friendBtn.layer.cornerRadius = 2.f;
_friendBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"mall/recommendFriend.png");
CGSize size = btnImageView.image.size;
[_friendBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_friendBtn.center);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _friendBtn;
}
- (UIButton*)weiboBtn {
if (!_weiboBtn) {
_weiboBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_weiboBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xce813e"])
forState:UIControlStateNormal];
[_weiboBtn addTarget:self action:@selector(weiboRecommend) forControlEvents:UIControlEventTouchUpInside];
[self setButtonHiligthAndDisableColor:_weiboBtn];
_weiboBtn.layer.cornerRadius = 2.f;
_weiboBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"mall/recommendWeibo.png");
CGSize size = btnImageView.image.size;
[_weiboBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_weiboBtn.center);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _weiboBtn;
}
- (UIButton*)QQZoneBtn {
if (!_QQZoneBtn) {
_QQZoneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_QQZoneBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xd5be37"])
forState:UIControlStateNormal];
[_QQZoneBtn addTarget:self action:@selector(qqZoneRecommend) forControlEvents:UIControlEventTouchUpInside];
if (![shareUtil isHaveQQClient]) {
_QQZoneBtn.enabled = NO;
}else {
_QQZoneBtn.enabled = YES;
}
[self setButtonHiligthAndDisableColor:_QQZoneBtn];
_QQZoneBtn.layer.cornerRadius = 2.f;
_QQZoneBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"mall/recommendQQZone.png");
CGSize size = btnImageView.image.size;
[_QQZoneBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_QQZoneBtn.center);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _QQZoneBtn;
}
- (UIButton*)QQBtn {
if (!_QQBtn) {
_QQBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_QQBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x5ca3e9"])
forState:UIControlStateNormal];
[_QQBtn addTarget:self action:@selector(qqRecommend) forControlEvents:UIControlEventTouchUpInside];
if (![shareUtil isHaveQQClient]) {
_QQBtn.enabled = NO;
}else {
_QQBtn.enabled = YES;
}
[self setButtonHiligthAndDisableColor:_QQBtn];
_QQBtn.layer.cornerRadius = 2.f;
_QQBtn.clipsToBounds = YES;
UIImageView *btnImageView = [[UIImageView alloc] init];
btnImageView.image = Image(@"mall/recommendQQ.png");
CGSize size = btnImageView.image.size;
[_QQBtn addSubview:btnImageView];
[btnImageView makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(_QQBtn.center);
make.height.equalTo(size.height);
make.width.equalTo(size.width);
}];
}
return _QQBtn;
}
- (UIView*)line {
if (!_line) {
_line = [UIView new];
_line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _line;
}
- (void)addBottomLine {
[self addSubview:self.line];
[self.line makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left).offset(10);
make.right.equalTo(self.right).offset(-10);
make.bottom.equalTo(self.bottom);
make.height.mas_equalTo(@0.5);
}];
}
- (void)setTaskInfo:(NSDictionary *)taskInfo {
self.titleLabel.text = taskInfo[@"title"];
self.seashellLabel.text = [NSString stringWithFormat:@"%@/%@", taskInfo[@"curSeashells"], taskInfo[@"maxSeashells"]];
}
- (void)setButtonHiligthAndDisableColor:(UIButton*)btn {
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK])
forState:UIControlStateHighlighted];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK])
forState:UIControlStateDisabled];
}
- (void)wechatRecommend {
if ([self.delegate respondsToSelector:@selector(wechatRecommend)]) {
[self.delegate wechatRecommend];
}
}
- (void)friendRecommend {
if ([self.delegate respondsToSelector:@selector(friendRecommend)]) {
[self.delegate friendRecommend];
}
}
- (void)weiboRecommend {
if ([self.delegate respondsToSelector:@selector(weiboRecommend)]) {
[self.delegate weiboRecommend];
}
}
- (void)qqZoneRecommend {
if ([self.delegate respondsToSelector:@selector(qqZoneRecommend)]) {
[self.delegate qqZoneRecommend];
}
}
- (void)qqRecommend {
if ([self.delegate respondsToSelector:@selector(qqRecommend)]) {
[self.delegate qqRecommend];
}
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|