123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- //
- // FKHomeInfoCell.m
- // FirstLink
- //
- // Created by jack on 15/12/25.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKHomePersonInfoCell.h"
- #import "FLImageHelper.h"
- #import "FKHomeViewModel.h"
- @interface FKHomePersonInfoCell ()
- @property (nonatomic, strong) UIImageView *headerBgView;
- @end
- @implementation FKHomePersonInfoCell
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- [self addAllSubViews];
- self.selectionStyle = UITableViewCellSelectionStyleNone;
- }
- return self;
- }
- - (void)fk_configWithViewModel:(FKHomeViewModel *)viewModel indexPath:(NSIndexPath *)indexPath {
- if ([viewModel isKindOfClass:[FKHomeViewModel class]]) {
- if (![FKUserManager isUserLogin]) {
- self.headView.avatarView.image = [UIImage imageNamed:@"UnloginIcon"];
-
- self.pointButton.hidden = YES;
- self.vipIcon.hidden = YES;
-
- self.nickLabel.text = @"点击登录或注册";
- self.nickLabel.font = [UIFont systemFontOfSize:16];
- [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headView.mas_right).offset(12);
- make.centerY.equalTo(self.headView);
- }];
- } else {
- User *user = [FKUserManager sharedManager].user;
- [self.headView.avatarView setImageWithURL:user.headurl placeholderImage:nil width:78 height:78];
-
- self.pointButton.hidden = NO;
- self.vipIcon.hidden = ![user isVIP];
-
- self.nickLabel.text = user.nickName;
- self.nickLabel.font = [UIFont systemFontOfSize:15];
-
- if ([user isVIP]) {
- [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.vipIcon.mas_right).offset(3);
- make.top.equalTo(self.contentView).offset(45);
- }];
- } else {
- [self.nickLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headView.mas_right).offset(12);
- make.top.equalTo(self.contentView).offset(45);
- }];
- }
-
- NSString *point = [NSString stringWithFormat:@"%@积分", [FLStringHelper replaceNilWithEmpty:viewModel.countModel.totalScore]];
- [self.pointButton setTitle:point forState:UIControlStateNormal];
- }
-
- if (viewModel.signModel && viewModel.signModel.signToday == NO) {
- self.signButton.hidden = NO;
- [self.signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignIcon"] forState:UIControlStateNormal];
- [self.signButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView);
- make.centerY.equalTo(self.headView);
- make.size.mas_equalTo(CGSizeMake(62, 25));
- }];
- } else {
- self.signButton.hidden = YES;
- }
- }
- }
- - (void)setShowSignedBtn {
- self.signButton.hidden = NO;
- [self.signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignedIcon"] forState:UIControlStateNormal];
- [self.signButton mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView);
- make.centerY.equalTo(self.headView);
- make.size.mas_equalTo(CGSizeMake(75, 25));
- }];
- }
- - (void)animationHideSignButtonCompletion:(void (^)(BOOL))completion {
- [UIView animateWithDuration:0.6 delay:0.6 options: UIViewAnimationOptionCurveEaseInOut animations: ^{
- CGRect frame = self.signButton.frame;
- self.signButton.center = CGPointMake(CGRectGetMaxX(frame) + CGRectGetWidth(frame)/2, CGRectGetMidY(frame));
- } completion: ^(BOOL finished) {
- completion(finished);
- }];
- }
- #pragma mark - Layout
- - (void)addAllSubViews {
- [self.contentView addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView);
- make.right.equalTo(self.contentView);
- make.top.equalTo(self.contentView);
- make.height.mas_equalTo([FKHomePersonInfoCell height]);
- }];
-
- [self.contentView addSubview:self.headerBgView];
- [self.headerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentView).offset(15);
- make.centerY.equalTo(self.contentView);
- }];
-
- [self.contentView addSubview:self.headView];
- [self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.headerBgView);
- make.size.mas_equalTo(CGSizeMake(78, 78));
- }];
-
- [self.contentView addSubview:self.vipIcon];
- [self.contentView addSubview:self.nickLabel];
- [self.vipIcon mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headView.mas_right).offset(12);
- make.centerY.equalTo(self.nickLabel.mas_centerY);
- }];
- [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.vipIcon.mas_right).offset(3);
- make.bottom.equalTo(self.headView.mas_centerY);
- }];
-
- [self.contentView addSubview:self.pointButton];
- [self.pointButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.headView.mas_right).offset(12);
- make.bottom.equalTo(self.contentView).offset(-45);
- make.size.mas_equalTo(CGSizeMake(105, 25));
- }];
-
- UIView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomePointArrow"]];
- [self.pointButton addSubview:imgView];
- [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.pointButton).offset(-1);
- make.right.equalTo(self.pointButton).offset(-10);
- }];
- [self.contentView addSubview:self.signButton];
- [self.signButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView);
- make.centerY.equalTo(self.headView);
- make.size.mas_equalTo(CGSizeMake(62, 25));
- }];
- }
- + (CGFloat)height {
- return (140);
- }
- #pragma mark - property
- - (UIImageView*)bgView {
- if (!_bgView) {
- _bgView = [[UIImageView alloc] init];
- UIImage *image = [FLImageHelper generateThumbnailFromTop:[UIImage imageNamed:@"homeHeaderBg"]
- frame:CGSizeMake(UISCREENWIDTH, [FKHomePersonInfoCell height])];
- _bgView.image = image;
- }
- return _bgView;
- }
- - (AvatarImageView *)headView {
- if (!_headView) {
- _headView = [[AvatarImageView alloc]initWithFrame:CGRectMake(0, 0, 78, 78)
- boardWidth:4.0f
- boardColor:[UIColor whiteColor]];
- _headView.backgroundColor = [UIColor whiteColor];
- _headView.userInteractionEnabled = YES;
- }
- return _headView;
- }
- - (UILabel *)nickLabel {
- if (!_nickLabel) {
- _nickLabel = [[UILabel alloc] init];
- _nickLabel.textColor = UIColorFromRGB(0x333333);
- _nickLabel.font = [UIFont boldSystemFontOfSize:15];
- _nickLabel.userInteractionEnabled = YES;
- }
- return _nickLabel;
- }
- - (UIButton*)pointButton {
- if (!_pointButton) {
- _pointButton = [[UIButton alloc] init];
- [_pointButton.titleLabel setFont:[UIFont systemFontOfSize:13]];
- [_pointButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
- [_pointButton setBackgroundImage:[UIImage imageNamed:@"Home_point_bg_icon"] forState:UIControlStateNormal];
- [_pointButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 2, 0)];
- }
- return _pointButton;
- }
- - (UIButton*)signButton {
- if (!_signButton) {
- _signButton = [[UIButton alloc] init];
- [_signButton setBackgroundImage:[UIImage imageNamed:@"HomeSignIcon"] forState:UIControlStateNormal];
- _signButton.hidden = YES;
- }
- return _signButton;
- }
- - (UIImageView *)vipIcon {
- if (!_vipIcon) {
- _vipIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"HomeVIPTagIcon"]];
- }
- return _vipIcon;
- }
- - (UIImageView *)headerBgView {
- if (!_headerBgView) {
- _headerBgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"headerShadowBg"]];
- }
- return _headerBgView;
- }
- @end
|