Sin descripción

FKHomePersonInfoCell.m 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. //
  2. // FKHomeInfoCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/12/25.
  6. // Copyright © 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKHomePersonInfoCell.h"
  9. #import "FLImageHelper.h"
  10. #import "FKHomeViewModel.h"
  11. @interface FKHomePersonInfoCell ()
  12. @property (nonatomic, strong) UIImageView *headerBgView;
  13. @end
  14. @implementation FKHomePersonInfoCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  16. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  17. if (self) {
  18. [self addAllSubViews];
  19. self.selectionStyle = UITableViewCellSelectionStyleNone;
  20. }
  21. return self;
  22. }
  23. - (void)fk_configWithViewModel:(FKHomeViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
  24. if ([viewModel isKindOfClass:[FKHomeViewModel class]]) {
  25. if (![FKUserManager isUserLogin]) {
  26. self.headView.avatarView.image = [UIImage imageNamed:@"UnloginIcon"];
  27. self.pointButton.hidden = YES;
  28. self.vipIcon.hidden = YES;
  29. self.nickLabel.text = @"点击登录或注册";
  30. self.nickLabel.font = [UIFont systemFontOfSize:16];
  31. [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  32. make.left.equalTo(self.headView.mas_right).offset(12);
  33. make.centerY.equalTo(self.headView);
  34. }];
  35. } else {
  36. User *user = [FKUserManager sharedManager].user;
  37. [self.headView.avatarView setImageWithURL:user.headurl placeholderImage:nil width:78 height:78];
  38. self.pointButton.hidden = NO;
  39. self.vipIcon.hidden = ![user isVIP];
  40. self.nickLabel.text = user.nickName;
  41. self.nickLabel.font = [UIFont systemFontOfSize:15];
  42. if ([user isVIP]) {
  43. [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  44. make.left.equalTo(self.vipIcon.mas_right).offset(3);
  45. make.top.equalTo(self.contentView).offset(45);
  46. }];
  47. } else {
  48. [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  49. make.left.equalTo(self.headView.mas_right).offset(12);
  50. make.top.equalTo(self.contentView).offset(45);
  51. }];
  52. }
  53. NSString *point = [NSString stringWithFormat:@"%@积分", [FLStringHelper replaceNilWithEmpty:viewModel.countModel.totalScore]];
  54. [self.pointButton setTitle:point forState:UIControlStateNormal];
  55. }
  56. if (viewModel.signModel && viewModel.signModel.signToday == NO) {
  57. self.signButton.hidden = NO;
  58. [self.signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignIcon"] forState:UIControlStateNormal];
  59. [self.signButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  60. make.right.equalTo(self.contentView);
  61. make.centerY.equalTo(self.headView);
  62. make.size.mas_equalTo(CGSizeMake(62, 25));
  63. }];
  64. } else {
  65. self.signButton.hidden = YES;
  66. }
  67. }
  68. }
  69. - (void)setShowSignedBtn {
  70. self.signButton.hidden = NO;
  71. [self.signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignedIcon"] forState:UIControlStateNormal];
  72. [self.signButton mas_remakeConstraints:^(MASConstraintMaker *make) {
  73. make.right.equalTo(self.contentView);
  74. make.centerY.equalTo(self.headView);
  75. make.size.mas_equalTo(CGSizeMake(75, 25));
  76. }];
  77. }
  78. - (void)animationHideSignButtonCompletion:(void (^)(BOOL))completion {
  79. [UIView animateWithDuration:0.6 delay:0.6 options: UIViewAnimationOptionCurveEaseInOut animations: ^{
  80. CGRect frame = self.signButton.frame;
  81. self.signButton.center = CGPointMake(CGRectGetMaxX(frame) + CGRectGetWidth(frame)/2, CGRectGetMidY(frame));
  82. } completion: ^(BOOL finished) {
  83. completion(finished);
  84. }];
  85. }
  86. #pragma mark - Layout
  87. - (void)addAllSubViews {
  88. [self.contentView addSubview:self.bgView];
  89. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.left.equalTo(self.contentView);
  91. make.right.equalTo(self.contentView);
  92. make.top.equalTo(self.contentView);
  93. make.height.mas_equalTo([FKHomePersonInfoCell height]);
  94. }];
  95. [self.contentView addSubview:self.headerBgView];
  96. [self.headerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.equalTo(self.contentView).offset(15);
  98. make.centerY.equalTo(self.contentView);
  99. }];
  100. [self.contentView addSubview:self.headView];
  101. [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.center.equalTo(self.headerBgView);
  103. make.size.mas_equalTo(CGSizeMake(78, 78));
  104. }];
  105. [self.contentView addSubview:self.vipIcon];
  106. [self.contentView addSubview:self.nickLabel];
  107. [self.vipIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.equalTo(self.headView.mas_right).offset(12);
  109. make.centerY.equalTo(self.nickLabel.mas_centerY);
  110. }];
  111. [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.equalTo(self.vipIcon.mas_right).offset(3);
  113. make.bottom.equalTo(self.headView.mas_centerY);
  114. }];
  115. [self.contentView addSubview:self.pointButton];
  116. [self.pointButton mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.left.equalTo(self.headView.mas_right).offset(12);
  118. make.bottom.equalTo(self.contentView).offset(-45);
  119. make.size.mas_equalTo(CGSizeMake(105, 25));
  120. }];
  121. UIView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomePointArrow"]];
  122. [self.pointButton addSubview:imgView];
  123. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  124. make.centerY.equalTo(self.pointButton).offset(-1);
  125. make.right.equalTo(self.pointButton).offset(-10);
  126. }];
  127. [self.contentView addSubview:self.signButton];
  128. [self.signButton mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.right.equalTo(self.contentView);
  130. make.centerY.equalTo(self.headView);
  131. make.size.mas_equalTo(CGSizeMake(62, 25));
  132. }];
  133. }
  134. + (CGFloat)height {
  135. return (140);
  136. }
  137. #pragma mark - property
  138. - (UIImageView*)bgView {
  139. if (!_bgView) {
  140. _bgView = [[UIImageView alloc] init];
  141. UIImage *image = [FLImageHelper generateThumbnailFromTop:[UIImage imageNamed:@"homeHeaderBg"]
  142. frame:CGSizeMake(UISCREENWIDTH, [FKHomePersonInfoCell height])];
  143. _bgView.image = image;
  144. }
  145. return _bgView;
  146. }
  147. - (AvatarImageView *)headView {
  148. if (!_headView) {
  149. _headView = [[AvatarImageView alloc]initWithFrame:CGRectMake(0, 0, 78, 78)
  150. boardWidth:4.0f
  151. boardColor:[UIColor whiteColor]];
  152. _headView.backgroundColor = [UIColor whiteColor];
  153. _headView.userInteractionEnabled = YES;
  154. }
  155. return _headView;
  156. }
  157. - (UILabel *)nickLabel {
  158. if (!_nickLabel) {
  159. _nickLabel = [[UILabel alloc] init];
  160. _nickLabel.textColor = UIColorFromRGB(0x333333);
  161. _nickLabel.font = [UIFont boldSystemFontOfSize:15];
  162. _nickLabel.userInteractionEnabled = YES;
  163. }
  164. return _nickLabel;
  165. }
  166. - (UIButton*)pointButton {
  167. if (!_pointButton) {
  168. _pointButton = [[UIButton alloc] init];
  169. [_pointButton.titleLabel setFont:[UIFont systemFontOfSize:13]];
  170. [_pointButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
  171. [_pointButton setBackgroundImage:[UIImage imageNamed:@"Home_point_bg_icon"] forState:UIControlStateNormal];
  172. [_pointButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 2, 0)];
  173. }
  174. return _pointButton;
  175. }
  176. - (UIButton*)signButton {
  177. if (!_signButton) {
  178. _signButton = [[UIButton alloc] init];
  179. [_signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignIcon"] forState:UIControlStateNormal];
  180. _signButton.hidden = YES;
  181. }
  182. return _signButton;
  183. }
  184. - (UIImageView *)vipIcon {
  185. if (!_vipIcon) {
  186. _vipIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomeVIPTagIcon"]];
  187. }
  188. return _vipIcon;
  189. }
  190. - (UIImageView *)headerBgView {
  191. if (!_headerBgView) {
  192. _headerBgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"headerShadowBg"]];
  193. }
  194. return _headerBgView;
  195. }
  196. @end