133 lines
4.3 KiB
Objective-C
133 lines
4.3 KiB
Objective-C
//
|
|
// XPRoomLicneseHourRankView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/6/13.
|
|
//
|
|
|
|
#import "XPRoomLicneseHourRankView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "RoomHalfHourRankModel.h"
|
|
|
|
@interface XPRoomLicneseHourRankView ()
|
|
|
|
///背景
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///围观
|
|
@property (nonatomic,strong) UIButton *enterButton;
|
|
|
|
@end
|
|
|
|
@implementation XPRoomLicneseHourRankView
|
|
|
|
- (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.backImageView];
|
|
[self addSubview:self.titleLabel];
|
|
[self addSubview:self.enterButton];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self).offset(64);
|
|
make.right.mas_equalTo(self.enterButton.mas_left).offset(-5);
|
|
make.centerY.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.enterButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(44, 20));
|
|
make.centerY.mas_equalTo(self);
|
|
make.right.mas_equalTo(self).offset(-6);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Event Response
|
|
- (void)backTapRecognizer {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomLicneseHourRankView:rankInfo:)]) {
|
|
[self.delegate xPRoomLicneseHourRankView:self rankInfo:self.licneseRankInfo];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setLicneseRankInfo:(RoomHalfHourRankModel *)licneseRankInfo {
|
|
_licneseRankInfo = licneseRankInfo;
|
|
if (_licneseRankInfo) {
|
|
NSString *nick = _licneseRankInfo.title;
|
|
if(nick.length > 6) {
|
|
nick = [NSString stringWithFormat:@"%@", [nick substringToIndex:6]];
|
|
}
|
|
NSDictionary * dic = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:[UIColor whiteColor]};
|
|
NSDictionary * hightDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:[ThemeColor appMainColor]};
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
[attribute appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"恭喜" attributes:dic]];
|
|
if (nick.length > 0) {
|
|
[attribute appendAttributedString:[[NSMutableAttributedString alloc] initWithString:nick attributes:hightDic]];
|
|
}
|
|
|
|
if (licneseRankInfo.desc.length > 0) {
|
|
[attribute appendAttributedString:[[NSMutableAttributedString alloc] initWithString:licneseRankInfo.desc attributes:dic]];
|
|
}
|
|
[attribute appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"TOP1" attributes:hightDic]];
|
|
self.titleLabel.attributedText = attribute;
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
}
|
|
}
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"room_licnese_hour_rank_bg"];
|
|
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backTapRecognizer)];
|
|
[_backImageView addGestureRecognizer:tap];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.numberOfLines = 2;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIButton *)enterButton {
|
|
if (!_enterButton) {
|
|
_enterButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_enterButton setTitle:@"去围观" forState:UIControlStateNormal];
|
|
[_enterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
_enterButton.titleLabel.font = [UIFont systemFontOfSize:10];
|
|
[_enterButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xd93d5f), UIColorFromRGB(0xfff494)] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal];
|
|
_enterButton.layer.masksToBounds = YES;
|
|
_enterButton.layer.cornerRadius = 10;
|
|
_enterButton.layer.borderColor = [UIColor whiteColor].CGColor;
|
|
_enterButton.layer.borderWidth = 0.5;
|
|
_enterButton.userInteractionEnabled = NO;
|
|
}
|
|
return _enterButton;
|
|
}
|
|
|
|
|
|
@end
|