XYLiveNobleListBottomView.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. //
  2. // XYLiveNobleListBottomView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/1/17.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYLiveNobleListBottomView.h"
  9. #import "XYLiveNobleListCellModel.h"
  10. @interface XYLiveNobleListBottomView ()
  11. // 非贵族显示的view
  12. @property (nonatomic, readwrite, strong) UIView *noNobleView;
  13. @property (nonatomic, readwrite, strong) UILabel *noNoblerTitleLabel;
  14. // 贵族view
  15. @property (nonatomic, readwrite, strong) UIView *nobleView;
  16. @property (nonatomic, readwrite, strong) UIImageView *headImageView;
  17. @property (nonatomic, readwrite, strong) UILabel *userNameLabel;
  18. @property (nonatomic, readwrite, strong) UILabel *timeLabel;
  19. /// 等级标志
  20. @property (nonatomic, readwrite, strong) XYUserLevelLabel *userLevelLabel;
  21. /// 贵族标志
  22. @property (nonatomic, readwrite, strong) UIImageView *nobleImageView;
  23. /// 守护标志
  24. @property (nonatomic, readwrite, strong) UIImageView *guardImageView;
  25. /// 粉丝团标志
  26. @property (nonatomic, readwrite, strong) UIImageView *fansImageView;
  27. @property (nonatomic, readwrite, strong) UIView *iphonexBottomEdgeView;
  28. @property (nonatomic, readwrite, strong) MASConstraint *userLevelWidthConstraint;
  29. @property (nonatomic, readwrite, strong) MASConstraint *nobleImageLeftConstraint;
  30. @property (nonatomic, readwrite, strong) MASConstraint *nobleImageWithConstraint;
  31. @property (nonatomic, readwrite, strong) MASConstraint *guardImageLeftConstraint;
  32. @property (nonatomic, readwrite, strong) MASConstraint *guardImageWithConstraint;
  33. @property (nonatomic, readwrite, strong) MASConstraint *fansImageLeftConstraint;
  34. @property (nonatomic, readwrite, strong) MASConstraint *fansImageWithConstraint;
  35. @end
  36. @implementation XYLiveNobleListBottomView
  37. #pragma mark - Public Method
  38. - (void)configureViewWithModel:(XYLiveNobleListCellModel *)model {
  39. if (StringIsNotEmpty(model.expirationTime)) {
  40. self.nobleView.hidden = NO;
  41. self.noNobleView.hidden = YES;
  42. [self.headImageView sd_setImageWithURL:UrlForString(model.userAvatar) placeholderImage:placeholderUserMainBgImage(model.userSex)];
  43. self.userNameLabel.text = model.userName;
  44. [self.userLevelLabel configUserLevel:model.wealthLevel shinyStatus:model.wealthMedalStatus];
  45. self.timeLabel.text = [NSString stringWithFormat:@"%@%@", kLocalizedString(@"到期时间:"), [SystemTimeObject timestampSwitchTime:model.expirationTime andFormatter:@"YYYY.MM.dd"]];
  46. if (model.wealthLevel == 0) {
  47. self.userLevelWidthConstraint.equalTo(@0);
  48. self.nobleImageLeftConstraint.equalTo(@0);
  49. }else {
  50. self.userLevelWidthConstraint.equalTo(@44);
  51. self.nobleImageLeftConstraint.equalTo(@4);
  52. }
  53. UIImage *nobleImage = [XYLevelImageHander getNobleImageWithLevel:model.nobleLevel];
  54. if (nobleImage) {
  55. self.nobleImageView.image = nobleImage;
  56. self.nobleImageWithConstraint.equalTo(@20.0f);
  57. self.guardImageLeftConstraint.equalTo(@4.0f);
  58. }else {
  59. self.nobleImageView.image = nil;
  60. self.nobleImageWithConstraint.equalTo(@0.0f);
  61. self.guardImageLeftConstraint.equalTo(@0.0f);
  62. }
  63. UIImage *guardImage = [XYLevelImageHander getGuardImageWithLevel:model.guardLevel];
  64. if (guardImage) {
  65. self.guardImageView.image = guardImage;
  66. self.guardImageWithConstraint.equalTo(@20.0f);
  67. self.fansImageLeftConstraint.equalTo(@4.0f);
  68. }else {
  69. self.guardImageView.image = nil;
  70. self.guardImageWithConstraint.equalTo(@0.0f);
  71. self.fansImageLeftConstraint.equalTo(@0.0f);
  72. }
  73. UIImage *fansImage = [XYLevelImageHander getFansImageWithLevel:model.fansLevel];
  74. if (fansImage) {
  75. self.fansImageView.image = fansImage;
  76. self.fansImageWithConstraint.equalTo(@20.0f);
  77. }else {
  78. self.fansImageView.image = nil;
  79. self.fansImageWithConstraint.equalTo(@0.0f);
  80. }
  81. }else {
  82. self.nobleView.hidden = YES;
  83. self.noNobleView.hidden = NO;
  84. }
  85. }
  86. #pragma mark - Private Method
  87. - (instancetype)initWithFrame:(CGRect)frame{
  88. if (self = [super initWithFrame:frame]) {
  89. // 初始化
  90. [self _setup];
  91. // 创建子控件
  92. [self _setupSubViews];
  93. // 布局子控件
  94. [self _makeSubViewsConstraints];
  95. }
  96. return self;
  97. }
  98. #pragma mark - 事件处理Or辅助方法
  99. #pragma mark - Private Method
  100. - (void)_setup{
  101. }
  102. #pragma mark - 创建子控件
  103. - (void)_setupSubViews{
  104. [self addSubview:self.noNobleView];
  105. [self.noNobleView addSubview:self.noNoblerTitleLabel];
  106. [self.noNobleView addSubview:self.openNoNobleButton];
  107. [self addSubview:self.nobleView];
  108. [self.nobleView addSubview:self.headImageView];
  109. [self.nobleView addSubview:self.userNameLabel];
  110. [self.nobleView addSubview:self.timeLabel];
  111. [self.nobleView addSubview:self.renewalButton];
  112. [self.nobleView addSubview:self.userLevelLabel];
  113. [self.nobleView addSubview:self.nobleImageView];
  114. [self.nobleView addSubview:self.guardImageView];
  115. [self.nobleView addSubview:self.fansImageView];
  116. [self iphonexBottomEdgeView];
  117. }
  118. #pragma mark - 布局子控件
  119. - (void)_makeSubViewsConstraints{
  120. [self.noNobleView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.edges.equalTo(self);
  122. }];
  123. [self.noNoblerTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.left.equalTo(self.noNobleView).offset(SPACING_EDGE);
  125. make.top.equalTo(self.noNobleView).offset(20.0f);
  126. }];
  127. [self.openNoNobleButton mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.right.equalTo(self.noNobleView).offset(-SPACING_EDGE);
  129. make.centerY.equalTo(self.noNoblerTitleLabel.mas_centerY).offset(0);
  130. make.width.equalTo(@95.0f);
  131. make.height.equalTo(@29.0f);
  132. }];
  133. [self.nobleView mas_makeConstraints:^(MASConstraintMaker *make) {
  134. make.edges.equalTo(self);
  135. }];
  136. [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  137. make.left.equalTo(self.nobleView).offset(SPACING_EDGE);
  138. make.top.equalTo(self.nobleView).offset(10.0f);
  139. make.width.height.equalTo(@40.0f);
  140. }];
  141. [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.equalTo(self.headImageView.mas_right).offset(10.0f);
  143. make.top.equalTo(self.nobleView).offset(12.0f);
  144. make.height.equalTo(@22.0f);
  145. }];
  146. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.left.equalTo(self.headImageView.mas_right).offset(10.0f);
  148. make.top.equalTo(self.userNameLabel.mas_bottom).offset(4.0f);
  149. make.height.equalTo(@14.0f);
  150. }];
  151. [self.userLevelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  152. make.left.equalTo(self.userNameLabel.mas_right).offset(4.0f);
  153. make.centerY.equalTo(self.userNameLabel);
  154. self.userLevelWidthConstraint = make.width.equalTo(@44.0f);
  155. make.height.equalTo(@20.0f);
  156. }];
  157. [self.nobleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  158. self.nobleImageLeftConstraint = make.left.equalTo(self.userLevelLabel.mas_right).offset(4.0f);
  159. make.centerY.equalTo(self.userNameLabel);
  160. self.nobleImageWithConstraint = make.width.equalTo(@20.0f);
  161. make.height.equalTo(@20.0f);
  162. }];
  163. [self.guardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  164. self.guardImageLeftConstraint = make.left.equalTo(self.nobleImageView.mas_right).offset(4.0f);
  165. make.centerY.equalTo(self.userNameLabel);
  166. self.guardImageWithConstraint = make.width.equalTo(@20.0f);
  167. make.height.equalTo(@20.0f);
  168. }];
  169. [self.fansImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  170. self.fansImageLeftConstraint = make.left.equalTo(self.guardImageView.mas_right).offset(4.0f);
  171. make.centerY.equalTo(self.userNameLabel);
  172. self.fansImageWithConstraint = make.width.equalTo(@20.0f);
  173. make.height.equalTo(@20.0f);
  174. make.right.lessThanOrEqualTo(self.renewalButton.mas_left).offset(-10.0f);
  175. }];
  176. [self.renewalButton mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.right.equalTo(self.nobleView).offset(-SPACING_EDGE);
  178. make.centerY.equalTo(self.headImageView.mas_centerY).offset(0);
  179. make.width.equalTo(@95.0f);
  180. make.height.equalTo(@30.0f);
  181. }];
  182. [self.openNoNobleButton addViewBorder:Color_Clear redian:16.0f];
  183. [self.headImageView addViewBorder:Color_Clear redian:20.0f];
  184. }
  185. - (UIView *)noNobleView {
  186. if (!_noNobleView) {
  187. _noNobleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.f_width, self.f_heigh)];
  188. }
  189. return _noNobleView;
  190. }
  191. - (UILabel *)noNoblerTitleLabel {
  192. if (!_noNoblerTitleLabel) {
  193. _noNoblerTitleLabel = [UILabel createLabelTextColor:[UIColor colorWithHexString:@"#999999" alpha:1] fount:Font(16)];
  194. _noNoblerTitleLabel.text = kLocalizedString(@"成为贵族,尊享不凡");
  195. if (ApplicationDelegate.isVersionStatus) {
  196. _noNoblerTitleLabel.hidden = YES;
  197. }
  198. }
  199. return _noNoblerTitleLabel;
  200. }
  201. - (UIView *)nobleView {
  202. if (!_nobleView) {
  203. _nobleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.f_width, self.f_heigh)];
  204. }
  205. return _nobleView;
  206. }
  207. - (UIImageView *)headImageView {
  208. if (!_headImageView) {
  209. _headImageView = [UIImageView new];
  210. _headImageView.contentMode = UIViewContentModeScaleToFill;
  211. }
  212. return _headImageView;
  213. }
  214. - (UILabel *)userNameLabel {
  215. if (!_userNameLabel) {
  216. _userNameLabel = [UILabel createLabelTextColor:Color_White fount:Font(16)];
  217. }
  218. return _userNameLabel;
  219. }
  220. - (UILabel *)timeLabel {
  221. if (!_timeLabel) {
  222. _timeLabel = [UILabel createLabelTextColor:ColorFromHexStringWithAlpha(@"#FFFFFF", 0.5f) fount:Font(10)];
  223. }
  224. return _timeLabel;
  225. }
  226. - (XYUserLevelLabel *)userLevelLabel {
  227. if (!_userLevelLabel) {
  228. _userLevelLabel = [[XYUserLevelLabel alloc] init];
  229. }
  230. return _userLevelLabel;
  231. }
  232. - (UIImageView *)nobleImageView {
  233. if (!_nobleImageView) {
  234. _nobleImageView = [UIImageView new];
  235. }
  236. return _nobleImageView;
  237. }
  238. - (UIImageView *)guardImageView {
  239. if (!_guardImageView) {
  240. _guardImageView = [UIImageView new];
  241. }
  242. return _guardImageView;
  243. }
  244. - (UIImageView *)fansImageView {
  245. if (!_fansImageView) {
  246. _fansImageView = [UIImageView new];
  247. }
  248. return _fansImageView;
  249. }
  250. - (UIButton *)openNoNobleButton {
  251. if (!_openNoNobleButton) {
  252. _openNoNobleButton = [UIButton createButtonTextColor:[UIColor colorWithHexString:@"#5D3106" alpha:1] textFont:Font(14)];
  253. [_openNoNobleButton setTitle:kLocalizedString(@"开通贵族") forState:UIControlStateNormal];
  254. _openNoNobleButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  255. _openNoNobleButton.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(95, 30) direction:GradientChangeDirectionLevel startColor:ColorFromHexString(@"#CEA46E") endColor:ColorFromHexString(@"#F5D0A2")];
  256. [_openNoNobleButton setTitleColor:[UIColor colorWithHexString:@"#15061A" alpha:1] forState:UIControlStateNormal];
  257. if (ApplicationDelegate.isVersionStatus) {
  258. _openNoNobleButton.hidden = YES;
  259. }
  260. kViewRadius(_openNoNobleButton, 15);
  261. }
  262. return _openNoNobleButton;
  263. }
  264. - (UIButton *)renewalButton {
  265. if (!_renewalButton) {
  266. _renewalButton = [UIButton createButtonTextColor:[UIColor colorWithHexString:@"#5D3106" alpha:1] textFont:Font(14)];
  267. [_renewalButton setTitle:[NSString stringWithFormat:@"%@ >", kLocalizedString(@"续费贵族 ")] forState:UIControlStateNormal];
  268. _renewalButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  269. _renewalButton.backgroundColor = [UIColor colorGradientChangeWithSize:CGSizeMake(95, 30) direction:GradientChangeDirectionLevel startColor:ColorFromHexString(@"#CEA46E") endColor:ColorFromHexString(@"#F5D0A2")];
  270. [_renewalButton setTitleColor:[UIColor colorWithHexString:@"#15061A" alpha:1] forState:UIControlStateNormal];
  271. if (ApplicationDelegate.isVersionStatus) {
  272. _renewalButton.hidden = YES;
  273. }
  274. kViewRadius(_renewalButton, 15);
  275. }
  276. return _renewalButton;
  277. }
  278. - (UIView *)iphonexBottomEdgeView{
  279. if (_iphonexBottomEdgeView == nil) {
  280. _iphonexBottomEdgeView = [[UIView alloc] initWithFrame:CGRectZero];
  281. _iphonexBottomEdgeView.backgroundColor = ColorFromHexStringWithAlpha(@"#15061A", 0.8f);
  282. [self addSubview:_iphonexBottomEdgeView];
  283. [_iphonexBottomEdgeView mas_makeConstraints:^(MASConstraintMaker *make) {
  284. make.left.mas_equalTo(0);
  285. make.right.mas_equalTo(0);
  286. make.bottom.mas_equalTo(kiPhoneXBottomEdge);
  287. make.height.offset(kiPhoneXBottomEdge);
  288. }];
  289. }
  290. return _iphonexBottomEdgeView;
  291. }
  292. @end