Files
yinmeng-ios/xplan-ios/Main/ModuleKit/SendGiftView/View/XPWeekStarInfoView.m

181 lines
5.7 KiB
Objective-C

//
// XPWeekStarInfoView.m
// xplan-ios
//
// Created by GreenLand on 2022/5/7.
//
#import "XPWeekStarInfoView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "XPMacro.h"
#import "ThemeColor+SendGift.h"
///Model
#import "XPWeekStarRankUserModel.h"
@interface XPWeekStarInfoView()
///冠名者标题
@property (nonatomic, strong) UILabel *charmTitleLabel;
///神豪标题
@property (nonatomic, strong) UILabel *contributeTitleLabel;
///冠名者
@property (nonatomic, strong) UILabel *charmLabel;
///神豪
@property (nonatomic, strong) UILabel *contributeLabel;
///周星版入口
@property (nonatomic, strong) UIButton *entranceButton;
///箭头
@property (nonatomic, strong) UIImageView *arrowImageView;
@end
@implementation XPWeekStarInfoView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.charmTitleLabel];
[self addSubview:self.contributeTitleLabel];
[self addSubview:self.charmLabel];
[self addSubview:self.contributeLabel];
[self addSubview:self.entranceButton];
[self addSubview:self.arrowImageView];
}
- (void)initSubViewConstraints {
[self.charmTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.mas_equalTo(0);
make.height.mas_equalTo(14);
}];
[self.charmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.charmTitleLabel.mas_right);
make.centerY.mas_equalTo(self.charmTitleLabel);
}];
[self.contributeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.charmLabel.mas_right).mas_offset(16);
make.centerY.mas_equalTo(self.charmTitleLabel);
}];
[self.contributeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contributeTitleLabel.mas_right);
make.centerY.mas_equalTo(self.charmTitleLabel);
}];
[self.entranceButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.arrowImageView.mas_left).mas_offset(-4);
make.width.mas_equalTo(48);
make.height.mas_equalTo(14);
make.centerY.mas_equalTo(self.charmTitleLabel);
}];
[self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(0);
make.width.mas_equalTo(7);
make.height.mas_equalTo(10);
make.centerY.mas_equalTo(self.charmTitleLabel);
}];
}
#pragma mark - events
- (void)didClickWeekStarRank:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPWeekStarInfoViewRankButtonClick)]) {
[self.delegate xPWeekStarInfoViewRankButtonClick];
}
}
#pragma mark - getter and setter
- (void)setFirstCharmRankUser:(XPWeekStarRankUserModel *)firstCharmRankUser {
NSString *nickStr = firstCharmRankUser.nick;
if (firstCharmRankUser.nick.length > 5) {
nickStr = [NSString stringWithFormat:@"%@…", [firstCharmRankUser.nick substringToIndex:5]];
} else if(!firstCharmRankUser.nick.length) {
nickStr = @"";
}
self.charmLabel.text = nickStr;
self.charmTitleLabel.text = firstCharmRankUser ? @"本周冠名者:" : @"";
}
- (void)setFirstLevelRankUser:(XPWeekStarRankUserModel *)firstLevelRankUser {
NSString *nickStr = firstLevelRankUser.nick;
if (firstLevelRankUser.nick.length > 5) {
nickStr = [NSString stringWithFormat:@"%@…", [firstLevelRankUser.nick substringToIndex:5]];
} else if(!firstLevelRankUser.nick.length) {
nickStr = @"";
}
self.contributeLabel.text = nickStr;
self.contributeTitleLabel.text = firstLevelRankUser ? @"周星神豪:" : @"";
}
- (UILabel *)charmTitleLabel {
if (!_charmTitleLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:10];
label.textColor = [ThemeColor giftSegmentNormalTitleColor];
label.text = @"本周冠名者:";
_charmTitleLabel = label;
}
return _charmTitleLabel;
}
- (UILabel *)contributeTitleLabel {
if (!_contributeTitleLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:10];
label.textColor = [ThemeColor giftSegmentNormalTitleColor];
label.text = @"周星神豪:";
_contributeTitleLabel = label;
}
return _contributeTitleLabel;
}
- (UILabel *)charmLabel {
if (!_charmLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:10];
label.textColor = [ThemeColor giftSegmentSelectTitleColor];
_charmLabel = label;
}
return _charmLabel;
}
- (UILabel *)contributeLabel {
if (!_contributeLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:10];
label.textColor = [ThemeColor giftSegmentSelectTitleColor];
_contributeLabel = label;
}
return _contributeLabel;
}
- (UIButton *)entranceButton {
if (!_entranceButton) {
_entranceButton = [UIButton buttonWithType:UIButtonTypeCustom];
_entranceButton.adjustsImageWhenHighlighted = NO;
[_entranceButton setBackgroundImage:[UIImage imageNamed:@"gift_bar_weekStar_button"] forState:UIControlStateNormal];
[_entranceButton addTarget:self action:@selector(didClickWeekStarRank:) forControlEvents:UIControlEventTouchUpInside];
}
return _entranceButton;
}
- (UIImageView *)arrowImageView {
if (!_arrowImageView) {
_arrowImageView = [[UIImageView alloc] init];
_arrowImageView.image = [UIImage imageNamed:@"gift_bar_weekStar_arrow"];
}
return _arrowImageView;
}
@end