117 lines
3.7 KiB
Objective-C
117 lines
3.7 KiB
Objective-C
//
|
|
// YMRoomAnchorRankBannerView.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2022/4/15.
|
|
//
|
|
|
|
#import "XPRoomAnchorRankBannerView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor+Room.h"
|
|
#import "DJDKMIMOMColor.h"
|
|
///Model
|
|
#import "RoomHalfHourRankModel.h"
|
|
///View
|
|
#import "NetImageView.h"
|
|
|
|
@interface XPRoomAnchorRankBannerView()
|
|
|
|
///背景
|
|
@property (nonatomic,strong) UIImageView *bgImageView;
|
|
///恭喜
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///围观
|
|
@property(nonatomic,strong) UIButton *lookUpBtn;
|
|
@end
|
|
|
|
@implementation XPRoomAnchorRankBannerView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.bgImageView];
|
|
[self.bgImageView addSubview:self.titleLabel];
|
|
[self.bgImageView addSubview:self.lookUpBtn];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
[self.lookUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(12));
|
|
make.width.mas_equalTo(kGetScaleWidth(60));
|
|
make.height.mas_equalTo(kGetScaleWidth(28));
|
|
make.centerY.equalTo(self.bgImageView);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.mas_equalTo(kGetScaleWidth(65));
|
|
make.trailing.equalTo(self.lookUpBtn.mas_leading).mas_offset(-kGetScaleWidth(7));
|
|
make.centerY.equalTo(self.bgImageView);
|
|
}];
|
|
}
|
|
|
|
- (void)setAnchorRankInfo:(RoomHalfHourRankModel *)anchorRankInfo {
|
|
_anchorRankInfo = anchorRankInfo;
|
|
if (anchorRankInfo) {
|
|
NSString *nick = _anchorRankInfo.nick;
|
|
if(nick.length > 5) {
|
|
nick = [NSString stringWithFormat:@"%@…", [nick substringToIndex:5]];
|
|
}
|
|
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomAnchorRankBannerView0"),nick];
|
|
NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc]initWithString:title attributes:@{NSFontAttributeName:kFontMedium(12),NSForegroundColorAttributeName:[UIColor whiteColor]}];
|
|
[titleAtt addAttributes:@{NSFontAttributeName:kFontMedium(12),NSForegroundColorAttributeName:UIColorFromRGB(0xF4FF48)} range:[title rangeOfString:nick]];
|
|
[titleAtt addAttributes:@{NSFontAttributeName:kFontMedium(12),NSForegroundColorAttributeName:UIColorFromRGB(0xF4FF48)} range:[title rangeOfString:YMLocalizedString(@"XPRoomAnchorRankBannerView1")]];
|
|
_titleLabel.attributedText = titleAtt;
|
|
}
|
|
}
|
|
-(void)lookUpAction{
|
|
if(self.delegate && [self.delegate respondsToSelector:@selector(xPRoomAnchorRankBannerView:rankInfo:)]){
|
|
[self.delegate xPRoomAnchorRankBannerView:self rankInfo:self.anchorRankInfo];
|
|
}
|
|
}
|
|
#pragma mark - Getters And Setters
|
|
- (UIImageView *)bgImageView {
|
|
if (!_bgImageView) {
|
|
_bgImageView = [[UIImageView alloc] init];
|
|
_bgImageView.image = [UIImage imageNamed:@"anchor_hour_rank_bg"];
|
|
}
|
|
return _bgImageView;
|
|
}
|
|
|
|
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
|
|
_titleLabel = label;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
|
|
- (UIButton *)lookUpBtn{
|
|
if(!_lookUpBtn){
|
|
_lookUpBtn = [UIButton new];
|
|
[_lookUpBtn setBackgroundImage:[UIImage getLanguageImage:@"anchor_hour_rank_icon"] forState:UIControlStateNormal];
|
|
[_lookUpBtn addTarget:self action:@selector(lookUpAction) forControlEvents:UIControlEventTouchUpInside];
|
|
}
|
|
return _lookUpBtn;
|
|
}
|
|
@end
|