FocusHeaderCollectReusView.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // FocusHeaderCollectReusView.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/29.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "FocusHeaderCollectReusView.h"
  9. @interface FocusHeaderCollectReusView ()
  10. @property(nonatomic, strong) UIView *lineView;
  11. @property (nonatomic,strong)UILabel *titleLabel;
  12. @property(nonatomic, strong) QMUIButton *randomBtn;
  13. @end
  14. static NSString *const image_name_btn = @"换一换";
  15. @implementation FocusHeaderCollectReusView
  16. - (instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. [self initUI];
  21. }
  22. return self;
  23. }
  24. - (void)initUI {
  25. self.backgroundColor = kWhiteColor;
  26. _lineView = ({
  27. UIView * view = [[UIView alloc] init];
  28. // view.backgroundColor = [UIColor colorWithHexString:@"#9D64FF"];
  29. // gradient
  30. // view.layer.cornerRadius = 1.5;
  31. view;
  32. });
  33. _titleLabel = ({
  34. UILabel * label = [[UILabel alloc]init];
  35. label.textColor = [UIColor colorWithHexString:@"#333333"];;
  36. label.font = [UIFont systemFontOfSize:16];
  37. label.text = ASLocalizedString(@"推荐主播");
  38. label;
  39. });
  40. _randomBtn = ({
  41. QMUIButton *btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  42. [btn setImage:[UIImage imageNamed:image_name_btn] forState:UIControlStateNormal];
  43. [btn setTitle:ASLocalizedString(@"换一换")forState:UIControlStateNormal];
  44. [btn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  45. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  46. btn.spacingBetweenImageAndTitle = 4;
  47. btn.imagePosition = QMUIButtonImagePositionLeft;
  48. [btn addTarget:self action:@selector(randomAction) forControlEvents:UIControlEventTouchUpInside];
  49. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  50. btn;
  51. });
  52. [self addSubview:_lineView];
  53. [self addSubview:_titleLabel];
  54. [self addSubview:_randomBtn];
  55. }
  56. - (void)randomAction{
  57. !self.randomBlock ? : self.randomBlock();
  58. }
  59. - (void)layoutSubviews {
  60. [super layoutSubviews];
  61. [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. // make.top.mas_equalTo(8);
  63. make.left.mas_equalTo(10);
  64. make.width.mas_equalTo(3);
  65. make.height.mas_equalTo(15);
  66. make.centerY.mas_equalTo(0);
  67. }];
  68. CAGradientLayer *gl = [CAGradientLayer layer];
  69. gl.frame = _lineView.bounds;
  70. gl.startPoint = CGPointMake(1, 0.5);
  71. gl.endPoint = CGPointMake(0, 0.5);
  72. gl.colors = @[(__bridge id)[UIColor colorWithRed:157/255.0 green:100/255.0 blue:255/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:240/255.0 green:96/255.0 blue:246/255.0 alpha:1.0].CGColor];
  73. gl.locations = @[@(0), @(1.0f)];
  74. [_lineView.layer addSublayer:gl];
  75. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.mas_equalTo(18);
  77. make.centerY.mas_equalTo(0);
  78. }];
  79. [_randomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.centerY.mas_equalTo(0);
  81. make.right.mas_equalTo(-10);
  82. make.width.mas_equalTo(80);
  83. }];
  84. }
  85. - (void)setSection:(NSInteger)section{
  86. if (section == 0) {
  87. _randomBtn.hidden = NO;
  88. _titleLabel.text = ASLocalizedString(@"推荐主播");
  89. } else {
  90. _randomBtn.hidden = YES;
  91. _titleLabel.text = ASLocalizedString(@"已关注主播");
  92. }
  93. }
  94. @end