123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- //
- // HomeSchoolHeadView.m
- // smartRhino
- //
- // Created by niuzhen on 2020/9/19.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeSchoolHeadView.h"
- @implementation HomeSchoolHeadView
- - (instancetype)init
- {
- if (self = [super init]) {
- [self setUpSubView];
- }
- return self;
- }
- - (void)setUpSubView
- {
- self.backgroundColor = UIColorHex(0xFFFFFF);
- [self addSubview:self.imagV];
- [self addSubview:self.showView];
- [self.imagV addSubview:self.playBtn];
- [self.showView addSubview:self.titleL];
- [self.showView addSubview:self.subTitleL];
- [self.showView addSubview:self.addressL];
- [self.showView addSubview:self.numL];
- [self.showView addSubview:self.typeL];
- [self.showView addSubview:self.collectBtn];
- [self.showView addSubview:self.iconV];
-
- self.showView.layer.shadowColor = UIColorHex(0x666666).CGColor;
- self.showView.layer.shadowOffset = CGSizeMake(2, 2);
- self.showView.layer.shadowOpacity = 8.f;
- self.showView.layer.shadowRadius = 10.f;
-
- [self.imagV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.mas_equalTo(self);
- make.height.mas_offset(183 * SCREEN_WIDTH / 375);
- }];
- [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.imagV);
- make.top.mas_offset(40);
- make.size.mas_offset(CGSizeMake(55, 55));
- }];
- [self.showView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_offset(15);
- make.right.mas_offset(-15);
- make.height.mas_offset(93);
- make.bottom.mas_offset(-6);
- }];
- [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.mas_offset(15);
- make.size.mas_offset(CGSizeMake(63, 63));
- }];
- [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(15);
- make.right.mas_offset(-15);
- make.size.mas_offset(CGSizeMake(50, 26));
- }];
- [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.iconV.mas_right).offset(15);
- make.top.mas_equalTo(self.iconV.mas_top);
- make.right.mas_equalTo(self.collectBtn.mas_left).offset(15);
- }];
- [self.subTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleL.mas_left);
- make.top.mas_equalTo(self.titleL.mas_bottom).offset(9);
- make.right.mas_equalTo(self.titleL.mas_right);
- }];
- }
- - (void)setDataWithModel:(HomeSubItemModel *)model
- {
- if (ISEmpty(model.VideoCoverImage)) {
- [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.VideoImage] placeholderImage:kPlaceHolderImage];
- }else{
- [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.VideoCoverImage] placeholderImage:kPlaceHolderImage];
- }
- [self.iconV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrl] placeholderImage:kPlaceHolderImage];
- NSArray * array = model.LableName;
- if (array.count == 3) {
- self.addressL.text = array[0];
- self.numL.text = array[1];
- self.typeL.text = array[2];
- }
- self.titleL.text = model.Name;
- self.subTitleL.text = model.ExtendLableName;
- [self.collectBtn setTitle:model.IsCollect ? @"已收藏" : @"收藏" forState:UIControlStateNormal];
- [self.collectBtn setBackgroundColor:model.IsCollect ? UIColorHex(0x666666) : UIColorHex(0xFAC364)];
- [self.addressL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.titleL.mas_left);
- make.top.mas_equalTo(self.subTitleL.mas_bottom).offset(9);
- make.size.mas_offset(CGSizeMake([self countLabel:self.addressL], 18));
- }];
-
- [self.numL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.addressL.mas_right).offset(5);
- make.top.mas_equalTo(self.addressL.mas_top);
- make.size.mas_offset(CGSizeMake([self countLabel:self.numL], 18));
- }];
- [self.typeL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.numL.mas_right).offset(5);
- make.top.mas_equalTo(self.addressL.mas_top);
- make.size.mas_offset(CGSizeMake([self countLabel:self.typeL], 18));
- }];
- self.imagV.userInteractionEnabled = YES;
- }
- - (CGFloat)countLabel:(UILabel *)label
- {
- CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 18)].width + 16.f;
- return W;
- }
- #pragma mark - SubView
- - (UIImageView *)imagV
- {
- if (!_imagV) {
- _imagV = [UIImageView new];
- // _imagV.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _imagV;
- }
- - (UIImageView *)iconV
- {
- if (!_iconV) {
- _iconV = [UIImageView new];
- _iconV.layer.cornerRadius = 4.f;
- _iconV.layer.masksToBounds = YES;
- }
- return _iconV;
- }
- - (UIView *)showView
- {
- if (!_showView) {
- _showView = [UIView new];
- _showView.layer.cornerRadius = 12.f;
- _showView.layer.masksToBounds = YES;
- _showView.backgroundColor = UIColorHex(0xFFFFFF);
- }
- return _showView;
- }
- - (UILabel *)titleL
- {
- if (!_titleL) {
- _titleL = [UILabel new];
- _titleL.font = [UIFont systemFontOfSize:15];
- _titleL.textColor = UIColorHex(0x222222);
- }
- return _titleL;
- }
- - (UILabel *)subTitleL
- {
- if (!_subTitleL) {
- _subTitleL = [UILabel new];
- _subTitleL.font = [UIFont systemFontOfSize:12];
- _subTitleL.textColor = UIColorHex(0x222222);
- }
- return _subTitleL;
- }
- - (UILabel *)addressL
- {
- if (!_addressL) {
- _addressL = [UILabel new];
- _addressL.font = [UIFont systemFontOfSize:10];
- _addressL.textColor = UIColorHex(0x666666);
- _addressL.backgroundColor = UIColorHex(0xF4F4F4);
- _addressL.layer.cornerRadius = 2.f;
- _addressL.textAlignment = NSTextAlignmentCenter;
- _addressL.layer.masksToBounds = YES;
- }
- return _addressL;
- }
- - (UILabel *)numL
- {
- if (!_numL) {
- _numL = [UILabel new];
- _numL.font = [UIFont systemFontOfSize:10];
- _numL.textColor = UIColorHex(0x666666);
- _numL.backgroundColor = UIColorHex(0xF4F4F4);
- _numL.layer.cornerRadius = 2.f;
- _numL.textAlignment = NSTextAlignmentCenter;
- _numL.layer.masksToBounds = YES;
- }
- return _numL;
- }
- - (UILabel *)typeL
- {
- if (!_typeL) {
- _typeL = [UILabel new];
- _typeL.font = [UIFont systemFontOfSize:10];
- _typeL.textColor = UIColorHex(0x666666);
- _typeL.backgroundColor = UIColorHex(0xF4F4F4);
- _typeL.layer.cornerRadius = 2.f;
- _typeL.textAlignment = NSTextAlignmentCenter;
- _typeL.layer.masksToBounds = YES;
- }
- return _typeL;
- }
- - (UIButton *)collectBtn
- {
- if (!_collectBtn) {
- _collectBtn = [UIButton new];
- [_collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
- [_collectBtn setBackgroundColor:UIColorHex(0xFAC364)];
- _collectBtn.titleLabel.font = [UIFont systemFontOfSize:14];
- [_collectBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
- _collectBtn.layer.cornerRadius = 4.f;
- _collectBtn.layer.masksToBounds = YES;
- }
- return _collectBtn;
- }
- - (UIButton *)playBtn
- {
- if (!_playBtn) {
- _playBtn = [UIButton new];
- [_playBtn setImage:IMG(@"HomeSchool_Play") forState:UIControlStateNormal];
- }
- return _playBtn;
- }
- @end
|