123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- //
- // FKProInfoCell.m
- // FirstLink
- //
- // Created by jack on 16/8/15.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKProInfoCell.h"
- #import "FKProDetailViewModel.h"
- @interface FKProInfoCell ()
- @property (nonatomic, strong) UILabel *headLabel;
- @property (nonatomic, strong) UILabel *originLabel;
- @property (nonatomic, strong) UILabel *translateLabel;
- @property (nonatomic, strong) UILabel *actionLabel;
- @property (nonatomic, strong) UIButton *arrowBtn;
- @end
- @implementation FKProInfoCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
- if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
- [self addAllSubviews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- [self.contentView addSubview:self.headLabel];
- [self.contentView addSubview:self.linkBtn];
- [self.contentView addSubview:self.originLabel];
- [self.contentView addSubview:self.translateLabel];
- [self.contentView addSubview:self.actionLabel];
- [self.contentView addSubview:self.arrowBtn];
- [self.contentView addSubview:self.actionBtn];
-
- [self.headLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView).offset(10);
- make.left.equalTo(self.contentView).offset(15);
- }];
-
- [self.linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.centerY.equalTo(self.headLabel);
- make.height.mas_equalTo(35);
- }];
-
- [self.originLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headLabel.mas_bottom).offset(12);
- make.centerX.equalTo(self.contentView);
- make.width.mas_equalTo(UISCREENWIDTH - 30);
- }];
-
- [self.actionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self.contentView).offset(- 5);
- make.top.equalTo(self.originLabel.mas_bottom).offset(15);
- }];
-
- [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.actionLabel.mas_right).offset(5);
- make.centerY.equalTo(self.actionLabel);
- }];
-
- [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.originLabel.mas_bottom);
- make.centerX.equalTo(self.contentView);
- make.size.mas_equalTo(CGSizeMake(250, 40));
- }];
-
- [self.translateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.actionLabel.mas_bottom).offset(15);
- make.left.right.equalTo(self.originLabel);
- }];
- }
- + (CGFloat)heightForUpText:(NSString *)upText
- downText:(NSString *)downText
- showTranslate:(BOOL)showTranslate{
-
- BOOL onlyOne = NO;
- if (![FLStringHelper isValidString:upText] && ![FLStringHelper isValidString:downText]) return 0; // 显示产品信息四个字
- if (![FLStringHelper isValidString:upText] || ![FLStringHelper isValidString:downText]) onlyOne = YES;
-
- if (onlyOne){
- NSString *upTargetText = downText;
- if ([FLStringHelper isValidString:upText]) upTargetText = upText;
-
- CGFloat orginH = [FLStringHelper sizeOfAttributeString:upTargetText
- lineSpace:2.4
- width:UISCREENWIDTH - 30
- font:[UIFont systemFontOfSize:13]
- maxRow:NSIntegerMax].height;
- return orginH + 60; // 只有一个
-
- }
-
- // 两个都存在
- CGFloat orginH = [FLStringHelper sizeOfAttributeString:upText
- lineSpace:2.4
- width:UISCREENWIDTH - 30
- font:[UIFont systemFontOfSize:13]
- maxRow:NSIntegerMax].height;
-
-
- if (showTranslate){
- CGFloat translateH = [FLStringHelper sizeOfAttributeString:downText
- lineSpace:2.4
- width:UISCREENWIDTH - 30
- font:[UIFont systemFontOfSize:13]
- maxRow:NSIntegerMax].height;
- return translateH + orginH + 100;
- }
- return orginH + 85;
- }
- - (void)setOrginStr:(NSString *)orginStr{
- if (![FLStringHelper isValidString:orginStr]){
- self.originLabel.text = nil;
- self.originLabel.attributedText = nil;
- return;
- }
-
- NSAttributedString *attStr = [FLStringHelper attStringWithText:orginStr lineSpace:2.4f];
- self.originLabel.attributedText = attStr;
- }
- - (void)setTranslateStr:(NSString *)translateStr{
- if (![FLStringHelper isValidString:translateStr]){
- self.translateLabel.text = nil;
- self.translateLabel.attributedText = nil;
- return;
- }
-
- NSAttributedString *attStr = [FLStringHelper attStringWithText:translateStr lineSpace:2.4f];
- self.translateLabel.attributedText = attStr;
- }
- - (void)setShowTranslate:(BOOL)showTranslate{
-
- self.translateLabel.hidden = showTranslate ? NO : YES;
- }
- - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
- if ([viewModel isKindOfClass:[FKProDetailViewModel class]]) {
-
- FKProDetailViewModel *detailModel = (FKProDetailViewModel *)viewModel;
- self.linkBtn.hidden = YES;
- if ([FLStringHelper isUrlString:detailModel.dataItem.productInfo.linkUrl]) {
- self.linkBtn.hidden = NO;
- }
-
- NSString *descChinese = detailModel.dataItem.productInfo.descChinese;
- NSString *descOrginal = detailModel.dataItem.productInfo.descOrginal;
-
- BOOL isAllEmpty = NO;
- BOOL isOnlyOne = NO;
- if (![FLStringHelper isValidString:descChinese] || ![FLStringHelper isValidString:descOrginal]) isOnlyOne = YES;
- if (![FLStringHelper isValidString:descChinese] && ![FLStringHelper isValidString:descOrginal]) isAllEmpty = YES;
-
- if ([detailModel.dataItem.supplier supplierType] == SupplierTypeOffline) {
- self.orginStr = descChinese;
- [self setTranslateActionStaus:YES];
- self.showTranslate = NO;
- return;
- }
-
- if (isOnlyOne ){
- // 只有一个
- self.orginStr = descOrginal;
- if ([FLStringHelper isValidString:descChinese]) self.orginStr = descChinese;
-
- [self setTranslateActionStaus:YES];
- self.showTranslate = NO;
- } else if (isAllEmpty){
- // 都空
- [self setTranslateActionStaus:YES];
- self.orginStr = nil;
- self.translateStr = nil;
- } else {
- self.orginStr = descChinese;
-
- [self setTranslateActionStaus:YES];
- self.showTranslate = detailModel.showTranslate;;
-
- BOOL selected = NO;
- NSString *title = @"查看原文";
- if (detailModel.showTranslate) {
- selected = YES;
- title = @"显示翻译";
- }
- self.actionLabel.text = title;
- self.arrowBtn.selected = selected;
-
- if ([FLStringHelper isValidString:descOrginal]){
- [self setTranslateActionStaus:NO];
- self.translateStr = descOrginal;
- }
- }
- }
- }
- - (void)setTranslateActionStaus:(BOOL)hiden{
- self.actionLabel.hidden = hiden;
- self.arrowBtn.hidden = hiden;
- self.actionBtn.hidden = hiden;
- }
- #pragma mark - property
- - (UILabel *)headLabel{
- if (_headLabel == nil) {
- _headLabel = [[UILabel alloc]init];
- _headLabel.textColor = UIColorFromRGB(0x333333);
- _headLabel.font = [UIFont systemFontOfSize:14];
- _headLabel.text = @"产品信息";
- }
- return _headLabel;
- }
- - (UIButton *)linkBtn{
- if (_linkBtn == nil) {
- _linkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_linkBtn setTitle:@" 商品原链接" forState:UIControlStateNormal];
- [_linkBtn setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
- [_linkBtn setImage:[UIImage imageNamed:@"link_icon"] forState:UIControlStateNormal];
- _linkBtn.titleLabel.font = [UIFont systemFontOfSize:13];
- _linkBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 15);
- _linkBtn.hidden = YES;
- }
- return _linkBtn;
- }
- - (UILabel *)originLabel{
- if (_originLabel == nil) {
- _originLabel = [[UILabel alloc]init];
- _originLabel.textColor = UIColorFromRGB(0x666666);
- _originLabel.font = [UIFont systemFontOfSize:13];
- _originLabel.numberOfLines = 0;
- [_originLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
- }
- return _originLabel;
- }
- - (UILabel *)translateLabel{
- if (_translateLabel == nil) {
- _translateLabel = [[UILabel alloc]init];
- _translateLabel.textColor = UIColorFromRGB(0x999999);
- _translateLabel.font = [UIFont systemFontOfSize:13];
- _translateLabel.numberOfLines = 0;
- }
- return _translateLabel;
- }
- - (UIButton *)actionBtn{
- if (_actionBtn == nil) {
- _actionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- }
- return _actionBtn;
- }
- - (UILabel *)actionLabel{
- if (_actionLabel == nil) {
- _actionLabel = [[UILabel alloc]init];
- _actionLabel.text = @"查看原文";
- _actionLabel.textColor = UIColorFromRGB(0x999999);
- _actionLabel.font = [UIFont systemFontOfSize:12];
- }
- return _actionLabel;
- }
- - (UIButton *)arrowBtn{
- if (_arrowBtn == nil) {
- _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_arrowBtn setImage:[UIImage imageNamed:@"basket_arrow_down"] forState:UIControlStateNormal];
- [_arrowBtn setImage:[UIImage imageNamed:@"basket_arrow_up"] forState:UIControlStateSelected];
- _arrowBtn.userInteractionEnabled = NO;
- }
- return _arrowBtn;
- }
- @end
|