// // receiveHeadView.m // Private-X // // Created by xd h on 2024/5/23. // #import "receiveHeadView.h" @interface receiveHeadView () { } @property(nonatomic,strong) UIView * selectBgView; @end @implementation receiveHeadView - (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; [self setBackgroundColor:[UIColor whiteColor]]; [self drawAnyView]; return self; } - (void)drawAnyView{ CGFloat curButtonW = SCREEN_W/2.0; CGFloat curButtonH = 40.0; _downLoadButton = [[UIButton alloc] init]; _downLoadButton.tag = 1; [_downLoadButton setTitle:NSLocalizedString(@"my_set_no_File_download",nil) forState:UIControlStateNormal]; [_downLoadButton setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal]; [_downLoadButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateSelected]; _downLoadButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_downLoadButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:_downLoadButton]; [_downLoadButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.width.mas_equalTo(curButtonW); make.top.mas_equalTo(0); make.height.mas_equalTo(curButtonH); }]; _saveButton = [[UIButton alloc] init]; _saveButton.tag = 2; [_saveButton setTitle:NSLocalizedString(@"receive_save_title",nil) forState:UIControlStateNormal]; [_saveButton setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal]; [_saveButton setTitleColor:[UIColor hwColor:@"#01B7EA" alpha:1.0] forState:UIControlStateSelected]; _saveButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; [_saveButton addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:_saveButton]; [_saveButton mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(curButtonW); make.width.mas_equalTo(curButtonW); make.top.mas_equalTo(0); make.height.mas_equalTo(curButtonH); }]; UIView *lineView = [[UIView alloc] init]; lineView.backgroundColor = [UIColor hwColor:@"#F9F9F9"]; [self addSubview:lineView]; [lineView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.height.mas_equalTo(1); make.bottom.mas_equalTo(0); }]; _downLoadButton.selected = YES; _selectBgView = [[UIView alloc] init]; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = CGRectMake(0, 0, 60, 3); gradientLayer.colors = @[(__bridge NSString *)[UIColor hwColor:@"#0CDEFD" alpha:1.0].CGColor, (__bridge NSString *)[UIColor hwColor:@"#058DFB" alpha:1.0].CGColor]; gradientLayer.locations = @[@(0), @(1.0f)]; [_selectBgView.layer addSublayer:gradientLayer]; //_selectBgView.backgroundColor = [UIColor whiteColor]; _selectBgView.layer.cornerRadius = 1.5; [self insertSubview:_selectBgView atIndex:0]; [_selectBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(_downLoadButton.mas_centerX); make.width.mas_equalTo(60); make.height.mas_equalTo(3); make.bottom.mas_equalTo(0); }]; } - (void)didClickButFun:(UIButton*)but { NSInteger tag = but.tag; //but.selected = !but.selected; [self changeSelectViewIndex:tag]; if(_didClickbuttonFun){ _didClickbuttonFun(tag); } } - (void)changeSelectViewIndex:(NSInteger)index { BOOL isSelectLeftType = YES; if(index == 2){ isSelectLeftType = NO; } _downLoadButton.selected = isSelectLeftType; _saveButton.selected = !isSelectLeftType; [_selectBgView mas_remakeConstraints:^(MASConstraintMaker *make) { if(isSelectLeftType){ make.centerX.mas_equalTo(_downLoadButton.mas_centerX); } else{ make.centerX.mas_equalTo(_saveButton.mas_centerX); } make.width.mas_equalTo(60); make.height.mas_equalTo(3); make.bottom.mas_equalTo(0); }]; } @end