// // topImageAndHotRecommendView.m // YouHuiProject // // Created by jcymac on 2018/9/10. // Copyright © 2018年 kuxuan. All rights reserved. // #import "topImageAndHotRecommendView.h" #import "KBTodayModelView2.h" @interface topImageAndHotRecommendView() @property(nonatomic,copy) NSString *imgUrl; @property(nonatomic,strong)NSArray *dataArray; @property(nonatomic,strong)UIImageView *imgView; @property(nonatomic,strong)UIView *contentView; @property(nonatomic,strong)UIView *titleView; @property(nonatomic,strong)KBTodayModelView2 *hotRecomendView; @end @implementation topImageAndHotRecommendView -(instancetype)initWithFrame:(CGRect)frame imgUrl:(NSString *)imgUrl title:(NSString *)title dataArray:(NSArray *)dataArray{ if (self=[super initWithFrame:frame]) { self.imgUrl=imgUrl; self.dataArray=dataArray; [self initUI]; [self adjustUI]; self.backgroundColor=[UIColor clearColor]; } return self; } -(void)initUI{ [self addSubview:self.imgView]; [self addSubview:self.contentView]; } -(void)adjustUI{ //更改headimage位置 [self.imgView sd_setImageWithURL:[NSURL URLWithString:self.imgUrl]]; float height=0; float imgY=0; if (self.imgUrl && ![self.imgUrl isEqualToString:@""]) { height=(self.width-FITSIZE(10))*303.0f/730; imgY=5; } self.imgView.frame=CGRectMake(FITSIZE(5), imgY, self.width-FITSIZE(10),height); //更改热门的位置 if (self.dataArray.count>0) { self.contentView.hidden=NO; self.contentView.y=self.imgView.bottom+5; }else{ self.contentView.hidden=YES; self.contentView.height=0; } self.height=self.contentView.bottom+5; } -(UIImageView *)imgView{ if (!_imgView) { _imgView=[[UIImageView alloc]init]; _imgView.layer.cornerRadius=8; _imgView.layer.masksToBounds=YES; } return _imgView; } -(KBTodayModelView2 *)hotRecomendView{ if (!_hotRecomendView) { _hotRecomendView = [[KBTodayModelView2 alloc] initWithFrame:CGRectMake(0, Fitsize(40), self.width-Fitsize(10), Fitsize(168)) titleNumOfLine:1]; _hotRecomendView.name=@""; _hotRecomendView.Id=@"0"; _hotRecomendView.backgroundColor=[UIColor clearColor]; [_hotRecomendView setGoodData:self.dataArray]; } return _hotRecomendView; } -(UIView *)titleView{ if (!_titleView) { _titleView=[[UIView alloc]initWithFrame:CGRectMake(Fitsize(5), 0, self.width-Fitsize(5), Fitsize(40))]; _titleView.backgroundColor=[UIColor clearColor]; UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, Fitsize(65), Fitsize(40))]; title.font = [UIFont systemFontOfSize:Fitsize(14)];//[UIColor homeRedColor] title.centerX = SCREEN_WIDTH/2; title.text = @"热门推荐"; [title sizeToFit]; title.textColor =[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x53F3FD] toColor:[UIColor YHColorWithHex:0x726BFF] withWidth:title.width]; [_titleView addSubview:title]; UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(title.left-20, 0, Fitsize(13), Fitsize(15))]; icon.centerY = title.centerY; icon.image = [UIImage imageNamed:@"hotRecom_left"]; [_titleView addSubview:icon]; UIImageView *icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(title.right+5, 0, Fitsize(13), Fitsize(15))]; icon2.centerY = title.centerY; icon2.image = [UIImage imageNamed:@"hotRecom_right"]; [_titleView addSubview:icon2]; } return _titleView; } -(UIView *)contentView{ if (!_contentView) { _contentView=[[UIView alloc]initWithFrame:CGRectMake(Fitsize(5), 0, self.width-Fitsize(10), Fitsize(208))]; _contentView.backgroundColor=[UIColor whiteColor]; _contentView.layer.cornerRadius=8; // _contentView.layer.masksToBounds=YES; [_contentView addSubview:self.titleView]; [_contentView addSubview:self.hotRecomendView]; } return _contentView; } @end