Brak opisu

DetailAuthorityCell.m 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // DetailAuthorityCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/8/25.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "DetailAuthorityCell.h"
  9. @interface DetailAuthorityCell ()
  10. @property (nonatomic, strong) UIButton *onlyVIP;
  11. @property (nonatomic, strong) UIButton *onlyNew;
  12. @property (nonatomic, strong) UIButton *postageFree;
  13. @end
  14. @implementation DetailAuthorityCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  16. {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. self.selectionStyle = UITableViewCellSelectionStyleNone;
  20. self.contentView.backgroundColor = [UIColor colorWithRed:234 / 255.0 green:234 / 255.0 blue:234 / 255.0 alpha:1.0];
  21. _authority = 0x00;
  22. }
  23. return self;
  24. }
  25. - (void)configWithDetailViewModel:(PindanDetailViewModel *)viewModel indexPath:(NSIndexPath *)indexPath{
  26. if (![viewModel isKindOfClass:[PindanDetailViewModel class]]) return;
  27. kDetailAuthority authority = 0x00;
  28. if ([viewModel isPostageFree]) authority = authority | kDetailAuthorityPostageFree;
  29. if ([viewModel isOnlyVIP]) authority = authority | kDetailAuthorityOnlyVIP;
  30. if ([viewModel isOnlyNew]) authority = authority | kDetailAuthorityOnlyNew;
  31. self.authority = authority;
  32. }
  33. #pragma mark - property
  34. - (UIButton *)onlyVIP{
  35. if (_onlyVIP == nil) {
  36. _onlyVIP = [UIButton buttonWithType:UIButtonTypeCustom];
  37. _onlyVIP.titleLabel.font = [UIFont systemFontOfSize:10];
  38. _onlyVIP.userInteractionEnabled = NO;
  39. [_onlyVIP setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
  40. [_onlyVIP setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
  41. [_onlyVIP setTitle:@" VIP会员专享" forState:UIControlStateNormal];
  42. }
  43. return _onlyVIP;
  44. }
  45. - (UIButton *)onlyNew{
  46. if (_onlyNew == nil) {
  47. _onlyNew = [UIButton buttonWithType:UIButtonTypeCustom];
  48. _onlyNew.titleLabel.font = [UIFont systemFontOfSize:10];
  49. _onlyNew.userInteractionEnabled = NO;
  50. [_onlyNew setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
  51. [_onlyNew setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
  52. [_onlyNew setTitle:@" 新用户专享" forState:UIControlStateNormal];
  53. }
  54. return _onlyNew;
  55. }
  56. - (UIButton *)postageFree{
  57. if (_postageFree == nil) {
  58. _postageFree = [UIButton buttonWithType:UIButtonTypeCustom];
  59. _postageFree.titleLabel.font = [UIFont systemFontOfSize:10];
  60. _postageFree.userInteractionEnabled = NO;
  61. [_postageFree setTitleColor:UIColorFromRGB(0x666666) forState:UIControlStateNormal];
  62. [_postageFree setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
  63. [_postageFree setTitle:@" 国内包邮" forState:UIControlStateNormal];
  64. }
  65. return _postageFree;
  66. }
  67. - (void)setAuthority:(kDetailAuthority)authority{
  68. if (authority == self.authority) return;
  69. [self.onlyNew removeFromSuperview];
  70. [self.onlyVIP removeFromSuperview];
  71. [self.postageFree removeFromSuperview];
  72. if (authority) {
  73. MASViewAttribute *constraint = self.contentView.mas_left;
  74. if (authority & kDetailAuthorityOnlyVIP) {
  75. [self.contentView addSubview:self.onlyVIP];
  76. [self.onlyVIP mas_remakeConstraints:^(MASConstraintMaker *make) {
  77. make.left.equalTo(self.contentView).offset(16);
  78. make.centerY.equalTo(self.contentView);
  79. }];
  80. constraint = self.onlyVIP.mas_right;
  81. }
  82. if (authority & kDetailAuthorityOnlyNew){
  83. [self.contentView addSubview:self.onlyNew];
  84. [self.onlyNew mas_remakeConstraints:^(MASConstraintMaker *make) {
  85. make.left.equalTo(constraint).offset(16);
  86. make.centerY.equalTo(self.contentView);
  87. }];
  88. constraint = self.onlyNew.mas_right;
  89. }
  90. if (authority & kDetailAuthorityPostageFree){
  91. [self.contentView addSubview:self.postageFree];
  92. [self.postageFree mas_remakeConstraints:^(MASConstraintMaker *make) {
  93. make.left.equalTo(constraint).offset(16);
  94. make.centerY.equalTo(self.contentView);
  95. }];
  96. }
  97. }
  98. }
  99. @end