口袋优选

topImageAndHotRecommendView.m 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // topImageAndHotRecommendView.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/9/10.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "topImageAndHotRecommendView.h"
  9. #import "KBTodayModelView2.h"
  10. @interface topImageAndHotRecommendView()
  11. @property(nonatomic,copy) NSString *imgUrl;
  12. @property(nonatomic,strong)NSArray *dataArray;
  13. @property(nonatomic,strong)UIImageView *imgView;
  14. @property(nonatomic,strong)UIView *contentView;
  15. @property(nonatomic,strong)UIView *titleView;
  16. @property(nonatomic,strong)KBTodayModelView2 *hotRecomendView;
  17. @end
  18. @implementation topImageAndHotRecommendView
  19. -(instancetype)initWithFrame:(CGRect)frame imgUrl:(NSString *)imgUrl title:(NSString *)title dataArray:(NSArray *)dataArray{
  20. if (self=[super initWithFrame:frame]) {
  21. self.imgUrl=imgUrl;
  22. self.dataArray=dataArray;
  23. [self initUI];
  24. [self adjustUI];
  25. self.backgroundColor=[UIColor clearColor];
  26. }
  27. return self;
  28. }
  29. -(void)initUI{
  30. [self addSubview:self.imgView];
  31. [self addSubview:self.contentView];
  32. }
  33. -(void)adjustUI{
  34. //更改headimage位置
  35. [self.imgView sd_setImageWithURL:[NSURL URLWithString:self.imgUrl]];
  36. float height=0;
  37. float imgY=0;
  38. if (self.imgUrl && ![self.imgUrl isEqualToString:@""]) {
  39. height=(self.width-FITSIZE(10))*303.0f/730;
  40. imgY=5;
  41. }
  42. self.imgView.frame=CGRectMake(FITSIZE(5), imgY, self.width-FITSIZE(10),height);
  43. //更改热门的位置
  44. if (self.dataArray.count>0) {
  45. self.contentView.hidden=NO;
  46. self.contentView.y=self.imgView.bottom+5;
  47. }else{
  48. self.contentView.hidden=YES;
  49. self.contentView.height=0;
  50. }
  51. self.height=self.contentView.bottom+5;
  52. }
  53. -(UIImageView *)imgView{
  54. if (!_imgView) {
  55. _imgView=[[UIImageView alloc]init];
  56. _imgView.layer.cornerRadius=8;
  57. _imgView.layer.masksToBounds=YES;
  58. }
  59. return _imgView;
  60. }
  61. -(KBTodayModelView2 *)hotRecomendView{
  62. if (!_hotRecomendView) {
  63. _hotRecomendView = [[KBTodayModelView2 alloc] initWithFrame:CGRectMake(0, Fitsize(40), self.width-Fitsize(10), Fitsize(168)) titleNumOfLine:1];
  64. _hotRecomendView.name=@"";
  65. _hotRecomendView.Id=@"0";
  66. _hotRecomendView.backgroundColor=[UIColor clearColor];
  67. [_hotRecomendView setGoodData:self.dataArray];
  68. }
  69. return _hotRecomendView;
  70. }
  71. -(UIView *)titleView{
  72. if (!_titleView) {
  73. _titleView=[[UIView alloc]initWithFrame:CGRectMake(Fitsize(5), 0, self.width-Fitsize(5), Fitsize(40))];
  74. _titleView.backgroundColor=[UIColor clearColor];
  75. UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, Fitsize(65), Fitsize(40))];
  76. title.font = [UIFont systemFontOfSize:Fitsize(14)];//[UIColor homeRedColor]
  77. title.centerX = SCREEN_WIDTH/2;
  78. title.text = @"热门推荐";
  79. [title sizeToFit];
  80. title.textColor =[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0x53F3FD] toColor:[UIColor YHColorWithHex:0x726BFF] withWidth:title.width];
  81. [_titleView addSubview:title];
  82. UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(title.left-20, 0, Fitsize(13), Fitsize(15))];
  83. icon.centerY = title.centerY;
  84. icon.image = [UIImage imageNamed:@"hotRecom_left"];
  85. [_titleView addSubview:icon];
  86. UIImageView *icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(title.right+5, 0, Fitsize(13), Fitsize(15))];
  87. icon2.centerY = title.centerY;
  88. icon2.image = [UIImage imageNamed:@"hotRecom_right"];
  89. [_titleView addSubview:icon2];
  90. }
  91. return _titleView;
  92. }
  93. -(UIView *)contentView{
  94. if (!_contentView) {
  95. _contentView=[[UIView alloc]initWithFrame:CGRectMake(Fitsize(5), 0, self.width-Fitsize(10), Fitsize(208))];
  96. _contentView.backgroundColor=[UIColor whiteColor];
  97. _contentView.layer.cornerRadius=8;
  98. // _contentView.layer.masksToBounds=YES;
  99. [_contentView addSubview:self.titleView];
  100. [_contentView addSubview:self.hotRecomendView];
  101. }
  102. return _contentView;
  103. }
  104. @end