123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- //
- // KBGoodsCommunityCell.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/11/9.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBGoodsCommunityCell.h"
- @interface KBGoodsCommunityCell ()
- @property (nonatomic, strong) UIImageView *icon;
- @property (nonatomic, strong) UILabel *nickName;
- @property (nonatomic, strong) UILabel *tagLb;
- @property (nonatomic, strong) UILabel *desLb;
- @property (nonatomic, strong) UIImageView *goodIcon;
- @property (nonatomic, strong) YYLabel *title;
- @property (nonatomic, strong) YYLabel *priceLb;
- @property (nonatomic, strong) YYLabel *disPrice;
- @property (nonatomic, strong) UILabel *ticketNum;
- @end
- @implementation KBGoodsCommunityCell
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- self.layer.cornerRadius = 6;
- self.backgroundColor = [UIColor whiteColor];
- [self initSubViews];
- }
- return self;
- }
- - (void)initSubViews {
- [self.contentView addSubview:self.icon];
- [self.contentView addSubview:self.nickName];
- [self.contentView addSubview:self.tagLb];
- [self.contentView addSubview:self.goodIcon];
- [self.contentView addSubview:self.desLb];
- [self.contentView addSubview:self.title];
- [self.contentView addSubview:self.priceLb];
- [self.contentView addSubview:self.disPrice];
- [self.contentView addSubview:self.ticketNum];
-
- [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(5);
- make.top.mas_equalTo(8);
- make.width.height.mas_equalTo(44);
- }];
-
- [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.icon.mas_right).mas_offset(7);
- make.top.mas_equalTo(self.icon).mas_offset(3);
- }];
-
- [self.desLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.nickName);
- make.bottom.mas_equalTo(self.icon).mas_offset(-3);
- }];
-
- [self.tagLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.nickName.mas_right).mas_offset(10);
- make.centerY.mas_equalTo(self.nickName.mas_centerY);
- make.height.mas_equalTo(16);
- }];
-
- [self.goodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.icon.mas_bottom).mas_offset(15);
- make.left.mas_equalTo(self.icon);
- make.width.height.mas_equalTo(100);
- }];
-
- [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.goodIcon);
- make.left.mas_equalTo(self.goodIcon.mas_right).mas_offset(8);
- make.right.mas_equalTo(-15);
- }];
-
- [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.title);
- make.bottom.mas_equalTo(self.goodIcon.mas_bottom).mas_offset(-3);
- }];
-
- [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.disPrice);
- make.bottom.mas_equalTo(self.disPrice.mas_top).mas_offset(-8);
- }];
-
- [self.ticketNum mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.goodIcon);
- make.right.mas_equalTo(-15);
- make.width.mas_equalTo(70);
- make.height.mas_equalTo(25);
- }];
- }
- - (void)setModel:(KBChildGoodModel *)model {
- [self.icon sd_setImageWithURL:[NSURL URLWithString:model.userinfo[@"headimg"]]];
- self.nickName.text = model.userinfo[@"nick"];
-
- NSString *tag = model.userinfo[@"savelevel"];
- CGSize size = [PublicFunction getAutoWidthWith:tag andSize:CGSizeMake(MAXFLOAT, 16) andFont:11];
- if (tag.length > 0) {
- self.tagLb.text = tag;
- [self.tagLb mas_updateConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(size.width+20);
- }];
- self.tagLb.hidden = NO;
- }else {
- self.tagLb.hidden = YES;
- }
-
-
- self.desLb.text = model.userinfo[@"desc"];
- [self.goodIcon sd_setImageWithURL:[NSURL URLWithString:model.img]];
-
- //标题
- UIImage *img;
- if ([model.shop_type isEqualToString:@"1"]) {
- img= [UIImage imageNamed:@"tm_shop"];
- }
- YYAnimatedImageView *imgeView = [[YYAnimatedImageView alloc] initWithImage:img];
- if ([model.shop_type isEqualToString:@"1"]) {
- imgeView.frame = CGRectMake(0, 0, 15, 15);
- }else {
- imgeView.frame = CGRectMake(0, 0, 0, 0);
- }
-
- NSMutableAttributedString *mua = [NSMutableAttributedString yy_attachmentStringWithContent:imgeView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imgeView.frame.size alignToFont:[UIFont systemFontOfSize:14] alignment:YYTextVerticalAlignmentCenter];
-
- NSMutableAttributedString *attri;
- if ([model.shop_type isEqualToString:@"1"]) {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.title]];
- }else {
- attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",model.title]];
- }
- [attri insertAttributedString:mua atIndex:0];
- attri.yy_font = [UIFont systemFontOfSize:14];
- attri.yy_color = [UIColor YHColorWithHex:0x444444];
- attri.yy_lineSpacing = 4;
- self.title.attributedText = attri;
-
- //券后价格
- NSString *disStr;
- if ([model.is_coupon boolValue]) {
- disStr = [NSString stringWithFormat:@"券后¥%.2f", [model.discount_price floatValue]];
- }else {
- disStr = [NSString stringWithFormat:@"折后¥%.2f", [model.discount_price floatValue]];
- }
- NSMutableAttributedString *disAttr = [[NSMutableAttributedString alloc] initWithString:disStr];
- [disAttr yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(0, 3)];
- [disAttr yy_setFont:[UIFont systemFontOfSize:16] range:NSMakeRange(3, disStr.length-3)];
- disAttr.yy_color = [UIColor homeRedColor];
- self.disPrice.attributedText = disAttr;
-
- //原价
- NSString *price = [NSString stringWithFormat:@"原价¥%.2f",[model.price floatValue]];
- NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:price];
- attrStr.yy_font = [UIFont systemFontOfSize:11];
- attrStr.yy_color = [UIColor YHColorWithHex:0x999999];
- YYTextDecoration *decoration = [YYTextDecoration decorationWithStyle:YYTextLineStyleSingle width:@(1) color:[UIColor YHColorWithHex:0x999999]];
- [attrStr yy_setTextStrikethrough:decoration range:NSMakeRange(3, price.length-3)];
- self.priceLb.attributedText = attrStr;
-
- self.ticketNum.text = [NSString stringWithFormat:@"%@元券",model.coupon_price];
- self.ticketNum.hidden = ![model.is_coupon boolValue];
- }
- #pragma mark -----
- - (UIImageView *)icon {
- if (!_icon) {
- _icon = [[UIImageView alloc] init];
- _icon.backgroundColor = [UIColor yhGrayColor];
- _icon.layer.cornerRadius = 22;
- _icon.layer.masksToBounds = YES;
- }
- return _icon;
- }
- - (UILabel *)nickName {
- if (!_nickName) {
- _nickName = [[UILabel alloc] init];
- _nickName.font = [UIFont systemFontOfSize:16];
- _nickName.textColor = [UIColor YHColorWithHex:0x333333];
- }
- return _nickName;
- }
- - (UILabel *)tagLb {
- if (!_tagLb) {
- _tagLb = [[UILabel alloc] init];
- _tagLb.font = [UIFont systemFontOfSize:11];
- _tagLb.textColor = [UIColor homeRedColor];
- _tagLb.layer.cornerRadius = 8;
- _tagLb.layer.borderColor = [UIColor homeRedColor].CGColor;
- _tagLb.layer.borderWidth = 1;
- _tagLb.textAlignment = NSTextAlignmentCenter;
- }
- return _tagLb;
- }
- - (UILabel *)desLb {
- if (!_desLb) {
- _desLb = [[UILabel alloc] init];
- _desLb.textColor = [UIColor YHColorWithHex:0x878585];
- _desLb.font = [UIFont systemFontOfSize:13];
- }
- return _desLb;
- }
- - (UIImageView *)goodIcon {
- if (!_goodIcon) {
- _goodIcon = [[UIImageView alloc] init];
- _goodIcon.backgroundColor = [UIColor yhGrayColor];
- _goodIcon.layer.cornerRadius = 6;
- }
- return _goodIcon;
- }
- - (YYLabel *)title {
- if (!_title) {
- _title = [[YYLabel alloc] init];
- _title.font = [UIFont systemFontOfSize:13];
- _title.displaysAsynchronously = YES;
- _title.numberOfLines = 2;
- _title.preferredMaxLayoutWidth = SCREEN_WIDTH-150;
- }
- return _title;
- }
- - (YYLabel *)disPrice {
- if (!_disPrice) {
- _disPrice = [[YYLabel alloc] init];
- _disPrice.displaysAsynchronously = YES;
- }
- return _disPrice;
- }
- - (YYLabel *)priceLb {
- if (!_priceLb) {
- _priceLb = [[YYLabel alloc] init];
- _priceLb.textColor = [UIColor YHColorWithHex:0xA2A0A0];
- _priceLb.font = [UIFont systemFontOfSize:12];
- _priceLb.displaysAsynchronously = YES;
-
- }
- return _priceLb;
- }
- - (UILabel *)ticketNum {
- if (!_ticketNum) {
- _ticketNum = [[UILabel alloc] init];
- _ticketNum.backgroundColor = [UIColor homeRedColor];
- _ticketNum.font = [UIFont systemFontOfSize:13];
- _ticketNum.textAlignment = NSTextAlignmentCenter;
- _ticketNum.textColor = [UIColor whiteColor];
- _ticketNum.layer.cornerRadius = 4;
- _ticketNum.layer.masksToBounds = YES;
- }
- return _ticketNum;
- }
- @end
|