123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // uploadFileRecordheadView.m
- // 隐私保护
- //
- // Created by xd h on 2023/11/15.
- //
- #import "uploadFileRecordheadView.h"
- @interface uploadFileRecordheadView()
- @property(nonatomic,strong) UIView *selectBgView;//
- @property(nonatomic,assign) CGFloat butWidth;//
- @end
- @implementation uploadFileRecordheadView
- - (id)initWithFrame:(CGRect)frame{
- self = [super initWithFrame:frame];
-
- [self drawAnyView];
-
- return self;
- }
- - (void)drawAnyView{
- [self setBackgroundColor:[UIColor hwColor:@"#F9F9F9" alpha:1.0]];
- self.layer.cornerRadius = 8;
- NSString *leftStr = NSLocalizedString(@"my_set_no_File_upload",nil);
- NSString *midStr = NSLocalizedString(@"my_set_no_File_download",nil);
- NSString *rightStr = NSLocalizedString(@"my_set_no_File_backups",nil);
- NSString *fourStr = NSLocalizedString(@"my_set_no_File_receive_title",nil);
- NSArray *titleArr = @[leftStr,midStr,rightStr,fourStr];
-
- _butWidth = (SCREEN_W - 30)/titleArr.count;
-
- NSString *languageCode = [NSLocale preferredLanguages][0];
-
- CGFloat fontSize = 14.0;
-
- if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
- {
- fontSize = 8;
- }
-
- for (NSInteger i=0; i<titleArr.count; i++) {
-
- NSString* title = titleArr[i];
-
- UIButton *but = [[UIButton alloc] init];
- but.tag = i+1;
- [but setTitle:title forState:UIControlStateNormal];
- [but setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal];
- [but setTitleColor:[UIColor hwColor:@"#0A132B" alpha:1.0] forState:UIControlStateSelected];
- but.titleLabel.font = [UIFont systemFontOfSize:fontSize];
- [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:but];
-
- [but mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(i*_butWidth);
- make.width.mas_equalTo(_butWidth);
- make.top.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- }];
-
- if(i==0){
- but.selected = YES;
-
- _selectBgView = [[UIView alloc] init];
- _selectBgView.backgroundColor = [UIColor whiteColor];
- _selectBgView.layer.cornerRadius = 8;
- [self insertSubview:_selectBgView atIndex:0];
-
- [_selectBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(10);
- make.width.mas_equalTo(_butWidth -20);
- make.top.mas_equalTo(6);
- make.bottom.mas_equalTo(-6);
- }];
- }
- }
-
- }
- #pragma mark 按钮点击
- - (void)didClickButFun:(UIButton*)but
- {
- NSInteger tag = but.tag;
-
- self.selectIndex = tag;
-
- if(_didClickButFun){
- _didClickButFun(tag);
- }
- }
- - (void)setSelectIndex:(NSInteger)selectIndex
- {
- _selectIndex = selectIndex;
-
- NSArray *subViews = [self subviews];
-
- for (UIButton *but in subViews) {
- if([but isKindOfClass:[UIButton class]]){
- if(but.tag == selectIndex){
- but.selected = YES;
- }
- else{
- but.selected = NO;
- }
- }
- }
-
- CGRect frame = _selectBgView.frame;
- frame.origin.x = (_selectIndex -1)* _butWidth + 10;
-
- [UIView animateWithDuration:0.2 animations:^{
- self->_selectBgView.frame = frame;
- }];
- }
- @end
|