|
//
// commodityCell.m
// ThePaperBase
//
// Created by Huixin on 15/10/27.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "commodityCell.h"
#import "AsyncImageView.h"
@interface commodityCell ()
@property(nonatomic, strong)UIButton *leftBtn;
@property(nonatomic, strong)AsyncImageView *leftImage;
@property(nonatomic, strong)UILabel *leftTitleLabel;
@property(nonatomic, strong)UILabel *leftNumLabel;
@property(nonatomic, strong)UILabel *leftSeashellLabel;
@property(nonatomic, strong)UIView *leftBottomLine;
@property(nonatomic, strong)UIView *verticalLine;
@property(nonatomic, strong)UIButton *rightBtn;
@property(nonatomic, strong)AsyncImageView *rightImage;
@property(nonatomic, strong)UILabel *rightTitleLabel;
@property(nonatomic, strong)UILabel *rightNumLabel;
@property(nonatomic, strong)UILabel *rightSeashellLabel;
@property(nonatomic, strong)UIView *rightBottomLine;
@property(nonatomic, strong)commodityBO *leftCommodity;
@property(nonatomic, strong)commodityBO *rightCommodity;
@end
@implementation commodityCell
- (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.contentView addSubview:self.verticalLine];
[self.contentView addSubview:self.leftBtn];
[self.leftBtn addSubview:self.leftImage];
[self.leftBtn addSubview:self.leftNumLabel];
[self.leftBtn addSubview:self.leftTitleLabel];
[self.leftBtn addSubview:self.leftSeashellLabel];
[self.contentView addSubview:self.leftBottomLine];
[self.contentView addSubview:self.rightBtn];
[self.rightBtn addSubview:self.rightImage];
[self.rightBtn addSubview:self.rightTitleLabel];
[self.rightBtn addSubview:self.rightNumLabel];
[self.rightBtn addSubview:self.rightSeashellLabel];
[self.contentView addSubview:self.rightBottomLine];
[self.contentView addSubview:self.rightBtn];
[self.rightBtn addSubview:self.rightImage];
[self.rightBtn addSubview:self.rightTitleLabel];
[self.rightBtn addSubview:self.rightNumLabel];
[self.rightBtn addSubview:self.rightSeashellLabel];
[self.contentView addSubview:self.rightBottomLine];
[self layoutViews];
}
return self;
}
- (UIButton*)leftBtn {
if (!_leftBtn) {
_leftBtn = [[UIButton alloc] init];
_leftBtn.exclusiveTouch = YES;
[_leftBtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
_leftBtn.backgroundColor = [UIColor clearColor];
}
return _leftBtn;
}
- (AsyncImageView*)leftImage {
if (!_leftImage) {
_leftImage = [[AsyncImageView alloc] init];
_leftImage.userInteractionEnabled = NO;
}
return _leftImage;
}
- (UILabel*)leftTitleLabel {
if (!_leftTitleLabel) {
_leftTitleLabel = [UILabel new];
_leftTitleLabel.backgroundColor = [UIColor clearColor];
_leftTitleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_leftTitleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_leftTitleLabel.numberOfLines = 0;
}
return _leftTitleLabel;
}
- (UILabel*)leftNumLabel {
if (!_leftNumLabel) {
_leftNumLabel = [UILabel new];
_leftNumLabel.backgroundColor = [UIColor clearColor];
_leftNumLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_leftNumLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
}
return _leftNumLabel;
}
- (UILabel*)leftSeashellLabel {
if (!_leftSeashellLabel) {
_leftSeashellLabel = [UILabel new];
_leftSeashellLabel.backgroundColor = [UIColor clearColor];
_leftSeashellLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_leftSeashellLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_leftSeashellLabel.text = @"海贝";
}
return _leftSeashellLabel;
}
- (UIView*)leftBottomLine {
if (!_leftBottomLine) {
_leftBottomLine = [UIView new];
_leftBottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _leftBottomLine;
}
- (UIView*)verticalLine {
if (!_verticalLine) {
_verticalLine = [UIView new];
_verticalLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _verticalLine;
}
- (UIButton*)rightBtn {
if (!_rightBtn) {
_rightBtn = [[UIButton alloc] init];
_rightBtn.exclusiveTouch = YES;
[_rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
_rightBtn.backgroundColor = [UIColor clearColor];
}
return _rightBtn;
}
- (AsyncImageView*)rightImage {
if (!_rightImage) {
_rightImage = [[AsyncImageView alloc] init];
_rightImage.userInteractionEnabled = NO;
}
return _rightImage;
}
- (UILabel*)rightTitleLabel {
if (!_rightTitleLabel) {
_rightTitleLabel = [UILabel new];
_rightTitleLabel.backgroundColor = [UIColor clearColor];
_rightTitleLabel.textColor = [UIColor colorWithHexString:TextBlack];
_rightTitleLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_rightTitleLabel.numberOfLines = 0;
}
return _rightTitleLabel;
}
- (UILabel*)rightNumLabel {
if (!_rightNumLabel) {
_rightNumLabel = [UILabel new];
_rightNumLabel.backgroundColor = [UIColor clearColor];
_rightNumLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_rightNumLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO);
}
return _rightNumLabel;
}
- (UILabel*)rightSeashellLabel {
if (!_rightSeashellLabel) {
_rightSeashellLabel = [UILabel new];
_rightSeashellLabel.backgroundColor = [UIColor clearColor];
_rightSeashellLabel.textColor = [UIColor colorWithHexString:BLUECOLOR];
_rightSeashellLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_rightSeashellLabel.text = @"海贝";
}
return _rightSeashellLabel;
}
- (UIView*)rightBottomLine {
if (!_rightBottomLine) {
_rightBottomLine = [UIView new];
_rightBottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _rightBottomLine;
}
- (void)layoutViews {
[self.verticalLine makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top);
make.bottom.equalTo(self.contentView.bottom);
make.centerX.equalTo(self.contentView.centerX);
make.width.mas_equalTo(@0.5);
}];
[self.leftBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top);
make.left.equalTo(self.contentView.left);
make.right.equalTo(self.verticalLine.left);
make.bottom.equalTo(self.leftBottomLine.top);
}];
[self.leftImage makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftBtn.top).offset(10);
make.left.equalTo(self.leftBtn.left).offset(10);
make.right.equalTo(self.leftBtn.right).offset(-10);
make.height.mas_equalTo(self.leftImage.width);
}];
[self.leftSeashellLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftNumLabel.right).offset(5);
make.right.equalTo(self.leftBtn.right).offset(-10);
make.bottom.equalTo(self.leftNumLabel.bottom);
make.height.mas_equalTo(@15);
}];
[self.leftBottomLine makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left);
make.right.equalTo(self.leftBtn.right);
make.bottom.equalTo(self.contentView.bottom).offset(-0.5);
make.height.mas_equalTo(@0.5);
}];
[self.leftTitleLabel makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftImage.bottom).offset(10);
make.left.equalTo(self.leftBtn.left).offset(10);
make.right.equalTo(self.leftBtn.right).offset(-10);
make.height.mas_equalTo(@15);
}];
[self.leftNumLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.bottom.equalTo(self.leftBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(@0);
}];
[self.rightBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.top);
make.left.equalTo(self.verticalLine.right);
make.right.equalTo(self.contentView.right);
make.bottom.equalTo(self.rightBottomLine.top);
}];
[self.rightImage makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.rightBtn.top).offset(10);
make.left.equalTo(self.rightBtn.left).offset(10);
make.right.equalTo(self.rightBtn.right).offset(-10);
make.height.mas_equalTo(self.rightImage.width);
}];
[self.rightTitleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.rightImage.bottom).offset(10);
make.left.equalTo(self.rightBtn.left).offset(10);
make.right.equalTo(self.rightBtn.right).offset(-10);
make.height.mas_equalTo(@15);
}];
[self.rightNumLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rightBtn.left).offset(10);
make.bottom.equalTo(self.rightBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(@0);
}];
[self.rightSeashellLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rightNumLabel.right).offset(5);
make.right.equalTo(self.rightBtn.right).offset(-10);
make.bottom.equalTo(self.rightNumLabel.bottom);
make.height.mas_equalTo(@15);
}];
[self.rightBottomLine makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rightBtn.left);
make.right.equalTo(self.rightBtn.right);
make.bottom.equalTo(self.contentView.bottom).offset(-0.5);
make.height.mas_equalTo(@0.5);
}];
}
- (void)layoutLeftView {
CGFloat height = [self.leftTitleLabel sizeThatFits:CGSizeMake((rect_screen.size.width-40.5)/2.0, 0)].height;
[self.leftTitleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftImage.bottom).offset(10);
make.left.equalTo(self.leftBtn.left).offset(10);
make.right.equalTo(self.leftBtn.right).offset(-10);
make.height.mas_equalTo(height);
}];
CGFloat numWidth = [self.leftNumLabel sizeThatFits:CGSizeMake(0, 16)].width;
[self.leftNumLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.bottom.equalTo(self.leftBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(numWidth);
}];
}
- (void)layoutRightView {
CGFloat height = [self.rightTitleLabel sizeThatFits:CGSizeMake((rect_screen.size.width-40.5)/2.0, 0)].height;
[self.rightTitleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.rightImage.bottom).offset(10);
make.left.equalTo(self.rightBtn.left).offset(10);
make.right.equalTo(self.rightBtn.right).offset(-10);
make.height.mas_equalTo(height);
}];
CGFloat numWidth = [self.rightNumLabel sizeThatFits:CGSizeMake(0, 16)].width;
[self.rightNumLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rightBtn.left).offset(10);
make.bottom.equalTo(self.rightBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(numWidth);
}];
}
- (void)setLeftCommodity:(commodityBO *)leftCommodity
leftHeight:(CGFloat)leftHeight
leftWidth:(CGFloat)leftWidth
RightCommodity:(commodityBO *)rightCommodity
rightHeight:(CGFloat)rightHeight
rightWidth:(CGFloat)rightWidth {
_leftCommodity = leftCommodity;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imageID = getImageNameFromURL(leftCommodity.pic);
NSString *rightImageId = getImageNameFromURL(rightCommodity.pic);
dispatch_async(dispatch_get_main_queue(), ^{
self.leftImage.imageUrl = leftCommodity.pic;
self.leftImage.imageId = imageID;
self.leftTitleLabel.text = leftCommodity.name;
self.leftNumLabel.text = leftCommodity.seashell;
[self.leftTitleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.leftImage.bottom).offset(10);
make.left.equalTo(self.leftBtn.left).offset(10);
make.right.equalTo(self.leftBtn.right).offset(-10);
make.height.mas_equalTo(leftHeight);
}];
[self.leftNumLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.bottom.equalTo(self.leftBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(leftWidth);
}];
// [self layoutLeftView];
if (rightCommodity != nil) {
_rightCommodity = rightCommodity;
self.rightBtn.hidden = NO;
self.rightBottomLine.hidden = NO;
self.rightImage.imageUrl = rightCommodity.pic;
self.rightImage.imageId = rightImageId;
self.rightTitleLabel.text = rightCommodity.name;
self.rightNumLabel.text = rightCommodity.seashell;
[self.rightTitleLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.rightImage.bottom).offset(10);
make.left.equalTo(self.rightBtn.left).offset(10);
make.right.equalTo(self.rightBtn.right).offset(-10);
make.height.mas_equalTo(rightHeight);
}];
[self.rightNumLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.rightBtn.left).offset(10);
make.bottom.equalTo(self.rightBtn.bottom).offset(-10);
make.height.mas_equalTo(@16);
make.width.mas_equalTo(rightWidth);
}];
// [self layoutRightView];
}
else {
self.rightBtn.hidden = YES;
self.rightBottomLine.hidden = YES;
}
});
});
}
- (void)leftBtnClick {
if (isNotIOS8) { //bug5795: 【适配性】ios7,4s手机,积分商城:点击卡片的效果错误
if ([self.delegate respondsToSelector:@selector(gotoCommodity:)]) {
[self.delegate gotoCommodity:self.leftCommodity];
}
}
else {
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.15 animations:^{
if (isIOS8)
weakSelf.leftImage.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
if (isIOS8)
weakSelf.leftImage.transform = CGAffineTransformMakeScale(1.00, 1.00);
if ([weakSelf.delegate respondsToSelector:@selector(gotoCommodity:)]) {
[weakSelf.delegate gotoCommodity:weakSelf.leftCommodity];
}
}];
}
}
- (void)rightBtnClick {
if (isNotIOS8) { //bug5795: 【适配性】ios7,4s手机,积分商城:点击卡片的效果错误
if ([self.delegate respondsToSelector:@selector(gotoCommodity:)]) {
[self.delegate gotoCommodity:self.rightCommodity];
}
}
else {
__weak typeof(self) weakSelf = self;
[UIView animateWithDuration:0.15 animations:^{
if (isIOS8)
weakSelf.rightImage.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
if (isIOS8)
weakSelf.rightImage.transform = CGAffineTransformMakeScale(1.00, 1.00);
if ([weakSelf.delegate respondsToSelector:@selector(gotoCommodity:)]) {
[weakSelf.delegate gotoCommodity:weakSelf.rightCommodity];
}
}];
}
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|