Files
yinmeng-ios/xplan-ios/Main/Home/View/SubViews/HomeSearchHijack/XPHomeSearchAwardView.m

154 lines
4.7 KiB
Mathematica
Raw Normal View History

//
// XPHomeSearchAwardView.m
// xplan-ios
//
// Created by GreenLand on 2022/11/16.
//
#import "XPHomeSearchAwardView.h"
#import "Masonry/Masonry.h"
#import "ThemeColor.h"
#import "XPMacro.h"
#import "NetImageView.h"
#import "TTPopup.h"
@interface XPHomeSearchAwardView()
///
@property (nonatomic, strong) UILabel *awardTitle;
///
@property (nonatomic, strong) UIButton *closeBtn;
///icon
@property (nonatomic, strong) NetImageView *awardImageView;
///
@property (nonatomic, strong) UILabel *giftTitle;
///
@property (nonatomic, strong) UILabel *giftDes;
@end
@implementation XPHomeSearchAwardView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initView];
[self initContraints];
}
return self;
}
- (void)initView {
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = 20;
self.layer.masksToBounds = YES;
[self addSubview:self.awardTitle];
[self addSubview:self.closeBtn];
[self addSubview:self.awardImageView];
[self addSubview:self.giftTitle];
[self addSubview:self.giftDes];
}
- (void)initContraints {
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(300, 220));
}];
[self.awardTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(16);
make.height.mas_equalTo(22);
make.centerX.mas_equalTo(self);
make.right.mas_equalTo(self.closeBtn.mas_left).mas_offset(-5);
}];
[self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(13);
make.right.mas_equalTo(-15);
make.width.height.mas_equalTo(20);
}];
[self.awardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.awardTitle.mas_bottom).mas_offset(17);
make.centerX.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(112, 90));
}];
[self.giftTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.awardImageView.mas_bottom).mas_offset(11);
make.centerX.mas_equalTo(self);
make.height.mas_equalTo(20);
make.left.mas_equalTo(8);
}];
[self.giftDes mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.giftTitle.mas_bottom).mas_offset(4);
make.centerX.mas_equalTo(self);
make.height.mas_equalTo(17);
make.left.mas_equalTo(8);
}];
}
- (void)onCloseBtnClick:(UIButton *)sender {
[TTPopup dismiss];
}
- (void)setData:(HomeSearchHijackAwardModel *)data {
self.awardImageView.imageUrl = data.awardUrl;
self.giftTitle.text = data.awardName;
}
#pragma mark - getter
- (UILabel *)awardTitle {
if (!_awardTitle) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
label.textColor = [ThemeColor mainTextColor];
label.text = @"不错哟~你获得了神秘奖励";
label.textAlignment = NSTextAlignmentCenter;
_awardTitle = label;
}
return _awardTitle;
}
- (UIButton *)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:[UIImage imageNamed:@"room_little_game_close"] forState:UIControlStateNormal];
[_closeBtn addTarget:self action:@selector(onCloseBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (NetImageView *)awardImageView {
if (!_awardImageView) {
NetImageConfig *config = [[NetImageConfig alloc] init];
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
_awardImageView = [[NetImageView alloc] initWithConfig:config];
_awardImageView.contentMode = UIViewContentModeScaleAspectFit;
_awardImageView.layer.masksToBounds = YES;
_awardImageView.layer.cornerRadius = 8;
}
return _awardImageView;
}
- (UILabel *)giftTitle {
if (!_giftTitle) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
label.textColor = [ThemeColor mainTextColor];
label.textAlignment = NSTextAlignmentCenter;
_giftTitle = label;
}
return _giftTitle;
}
- (UILabel *)giftDes {
if (!_giftDes) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
label.textColor = [ThemeColor secondTextColor];
label.text = @"奖励已自动发放";
label.textAlignment = NSTextAlignmentCenter;
_giftDes = label;
}
return _giftDes;
}
@end