97 lines
2.8 KiB
Objective-C
97 lines
2.8 KiB
Objective-C
//
|
|
// XPNewHomeItemView.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2023/9/1.
|
|
//
|
|
|
|
#import "XPNewHomeItemView.h"
|
|
@interface XPNewHomeItemView()
|
|
///背景
|
|
@property(nonatomic,strong) UIImageView *bgImageView;
|
|
//标题
|
|
@property(nonatomic,strong) UILabel *titleView;
|
|
///副标题
|
|
@property(nonatomic,strong) UILabel *subTitleView;
|
|
@property(nonatomic,assign) int type;
|
|
@end
|
|
|
|
@implementation XPNewHomeItemView
|
|
|
|
-(instancetype)initWithFrame:(CGRect)frame type:(int)type{
|
|
self = [super initWithFrame:frame];
|
|
if(self){
|
|
[self installUI];
|
|
[self installConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)installUI{
|
|
[self addSubview:self.bgImageView];
|
|
[self.bgImageView addSubview:self.titleView];
|
|
[self.bgImageView addSubview:self.subTitleView];
|
|
}
|
|
-(void)installConstraints{
|
|
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
if(self.type == 0){
|
|
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(25));
|
|
make.leading.mas_equalTo(kGetScaleWidth(11));
|
|
make.height.mas_equalTo(kGetScaleWidth(18));
|
|
}];
|
|
[self.subTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(49));
|
|
make.leading.mas_equalTo(kGetScaleWidth(11));
|
|
make.height.mas_equalTo(kGetScaleWidth(17));
|
|
}];
|
|
return;
|
|
}
|
|
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(22));
|
|
make.leading.mas_equalTo(kGetScaleWidth(11));
|
|
make.height.mas_equalTo(kGetScaleWidth(18));
|
|
}];
|
|
[self.subTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(kGetScaleWidth(46));
|
|
make.leading.mas_equalTo(kGetScaleWidth(11));
|
|
make.height.mas_equalTo(kGetScaleWidth(17));
|
|
}];
|
|
}
|
|
#pragma mark - 赋值
|
|
- (void)setBgImage:(UIImage *)bgImage{
|
|
_bgImage = bgImage;
|
|
_bgImageView.image = bgImage;
|
|
}
|
|
- (void)setTitle:(NSString *)title{
|
|
_title = title;
|
|
_titleView.text = _title;
|
|
}
|
|
- (void)setSubTitle:(NSString *)subTitle{
|
|
_subTitle = subTitle;
|
|
_subTitleView.text = _subTitle;
|
|
}
|
|
#pragma mark - 懒加载
|
|
- (UIImageView *)bgImageView{
|
|
if(!_bgImageView){
|
|
_bgImageView = [UIImageView new];
|
|
_bgImageView.userInteractionEnabled = YES;
|
|
}
|
|
return _bgImageView;
|
|
}
|
|
- (UILabel *)titleView{
|
|
if(!_titleView){
|
|
_titleView = [UILabel labelInitWithText:@"" font:kFontBold(18) textColor:[UIColor whiteColor]];
|
|
}
|
|
return _titleView;
|
|
}
|
|
- (UILabel *)subTitleView{
|
|
if(!_subTitleView){
|
|
_subTitleView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[UIColor colorWithWhite:1 alpha:0.8]];
|
|
}
|
|
return _subTitleView;
|
|
}
|
|
@end
|