receiveHeadView.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // receiveHeadView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/23.
  6. //
  7. #import "receiveHeadView.h"
  8. @interface receiveHeadView ()
  9. {
  10. }
  11. @property(nonatomic,strong) UIView * selectBgView;
  12. @end
  13. @implementation receiveHeadView
  14. - (id)initWithFrame:(CGRect)frame{
  15. self = [super initWithFrame:frame];
  16. [self setBackgroundColor:[UIColor whiteColor]];
  17. [self drawAnyView];
  18. return self;
  19. }
  20. - (void)drawAnyView{
  21. CGFloat curButtonW = SCREEN_W/2.0;
  22. CGFloat curButtonH = 40.0;
  23. _downLoadButton = [[UIButton alloc] init];
  24. _downLoadButton.tag = 1;
  25. [_downLoadButton setTitle:NSLocalizedString(@"my_set_no_File_download",nil) forState:UIControlStateNormal];
  26. [_downLoadButton setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal];
  27. [_downLoadButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateSelected];
  28. _downLoadButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  29. [_downLoadButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  30. [self addSubview:_downLoadButton];
  31. [_downLoadButton mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.mas_equalTo(0);
  33. make.width.mas_equalTo(curButtonW);
  34. make.top.mas_equalTo(0);
  35. make.height.mas_equalTo(curButtonH);
  36. }];
  37. _saveButton = [[UIButton alloc] init];
  38. _saveButton.tag = 2;
  39. [_saveButton setTitle:NSLocalizedString(@"receive_save_title",nil) forState:UIControlStateNormal];
  40. [_saveButton setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal];
  41. [_saveButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateSelected];
  42. _saveButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  43. [_saveButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  44. [self addSubview:_saveButton];
  45. [_saveButton mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(curButtonW);
  47. make.width.mas_equalTo(curButtonW);
  48. make.top.mas_equalTo(0);
  49. make.height.mas_equalTo(curButtonH);
  50. }];
  51. UIView *lineView = [[UIView alloc] init];
  52. lineView.backgroundColor = [UIColor hwColor:@"#F9F9F9"];
  53. [self addSubview:lineView];
  54. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(0);
  56. make.right.mas_equalTo(0);
  57. make.height.mas_equalTo(1);
  58. make.bottom.mas_equalTo(0);
  59. }];
  60. _downLoadButton.selected = YES;
  61. _selectBgView = [[UIView alloc] init];
  62. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  63. gradientLayer.frame = CGRectMake(0, 0, 60, 3);
  64. gradientLayer.colors = @[(__bridge NSString *)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge NSString *)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor];
  65. gradientLayer.locations = @[@(0), @(1.0f)];
  66. [_selectBgView.layer addSublayer:gradientLayer];
  67. //_selectBgView.backgroundColor = [UIColor whiteColor];
  68. _selectBgView.layer.cornerRadius = 1.5;
  69. [self insertSubview:_selectBgView atIndex:0];
  70. [_selectBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.centerX.mas_equalTo(_downLoadButton.mas_centerX);
  72. make.width.mas_equalTo(60);
  73. make.height.mas_equalTo(3);
  74. make.bottom.mas_equalTo(0);
  75. }];
  76. }
  77. - (void)didClickButFun:(UIButton*)but
  78. {
  79. NSInteger tag = but.tag;
  80. //but.selected = !but.selected;
  81. [self changeSelectViewIndex:tag];
  82. if(_didClickbuttonFun){
  83. _didClickbuttonFun(tag);
  84. }
  85. }
  86. - (void)changeSelectViewIndex:(NSInteger)index
  87. {
  88. BOOL isSelectLeftType = YES;
  89. if(index == 2){
  90. isSelectLeftType = NO;
  91. }
  92. _downLoadButton.selected = isSelectLeftType;
  93. _saveButton.selected = !isSelectLeftType;
  94. [_selectBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
  95. if(isSelectLeftType){
  96. make.centerX.mas_equalTo(_downLoadButton.mas_centerX);
  97. }
  98. else{
  99. make.centerX.mas_equalTo(_saveButton.mas_centerX);
  100. }
  101. make.width.mas_equalTo(60);
  102. make.height.mas_equalTo(3);
  103. make.bottom.mas_equalTo(0);
  104. }];
  105. }
  106. @end