123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // DetailAuthorityCell.m
- // FirstLink
- //
- // Created by jack on 15/8/25.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "DetailAuthorityCell.h"
- @interface DetailAuthorityCell ()
- @property (nonatomic, strong) UIButton *onlyVIP;
- @property (nonatomic, strong) UIButton *onlyNew;
- @property (nonatomic, strong) UIButton *postageFree;
- @end
- @implementation DetailAuthorityCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- self.contentView.backgroundColor = [UIColor colorWithRed:234 / 255.0 green:234 / 255.0 blue:234 / 255.0 alpha:1.0];
- _authority = 0x00;
- }
- return self;
- }
- - (void)configWithDetailViewModel:(PindanDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{
-
- if (![viewModel isKindOfClass:[PindanDetailViewModel class]]) return;
-
- kDetailAuthority authority = 0x00;
- if ([viewModel isPostageFree]) authority = authority | kDetailAuthorityPostageFree;
- if ([viewModel isOnlyVIP]) authority = authority | kDetailAuthorityOnlyVIP;
- if ([viewModel isOnlyNew]) authority = authority | kDetailAuthorityOnlyNew;
- self.authority = authority;
- }
- #pragma mark - property
- - (UIButton *)onlyVIP{
- if (_onlyVIP == nil) {
- _onlyVIP = [UIButton buttonWithType:UIButtonTypeCustom];
- _onlyVIP.titleLabel.font = [UIFont systemFontOfSize:10];
- _onlyVIP.userInteractionEnabled = NO;
- [_onlyVIP setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
- [_onlyVIP setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
- [_onlyVIP setTitle:@" VIP会员专享" forState:UIControlStateNormal];
- }
- return _onlyVIP;
- }
- - (UIButton *)onlyNew{
- if (_onlyNew == nil) {
- _onlyNew = [UIButton buttonWithType:UIButtonTypeCustom];
- _onlyNew.titleLabel.font = [UIFont systemFontOfSize:10];
- _onlyNew.userInteractionEnabled = NO;
- [_onlyNew setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
- [_onlyNew setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
- [_onlyNew setTitle:@" 新用户专享" forState:UIControlStateNormal];
- }
- return _onlyNew;
- }
- - (UIButton *)postageFree{
- if (_postageFree == nil) {
- _postageFree = [UIButton buttonWithType:UIButtonTypeCustom];
- _postageFree.titleLabel.font = [UIFont systemFontOfSize:10];
- _postageFree.userInteractionEnabled = NO;
- [_postageFree setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
- [_postageFree setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
- [_postageFree setTitle:@" 国内包邮" forState:UIControlStateNormal];
- }
- return _postageFree;
- }
- - (void)setAuthority:(kDetailAuthority)authority{
-
- if (authority == self.authority) return;
-
- [self.onlyNew removeFromSuperview];
- [self.onlyVIP removeFromSuperview];
- [self.postageFree removeFromSuperview];
-
- if (authority) {
- MASViewAttribute *constraint = self.contentView.mas_left;
- if (authority & kDetailAuthorityOnlyVIP) {
- [self.contentView addSubview:self.onlyVIP];
- [self.onlyVIP mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(16);
- make.centerY.equalTo(self.contentView);
- }];
- constraint = self.onlyVIP.mas_right;
- }
- if (authority & kDetailAuthorityOnlyNew){
- [self.contentView addSubview:self.onlyNew];
- [self.onlyNew mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(constraint).offset(16);
- make.centerY.equalTo(self.contentView);
- }];
- constraint = self.onlyNew.mas_right;
- }
- if (authority & kDetailAuthorityPostageFree){
- [self.contentView addSubview:self.postageFree];
- [self.postageFree mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(constraint).offset(16);
- make.centerY.equalTo(self.contentView);
- }];
- }
- }
-
- }
- @end
|