uploadFileRecordheadView.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // uploadFileRecordheadView.m
  3. // 隐私保护
  4. //
  5. // Created by xd h on 2023/11/15.
  6. //
  7. #import "uploadFileRecordheadView.h"
  8. @interface uploadFileRecordheadView()
  9. @property(nonatomic,strong) UIView *selectBgView;//
  10. @property(nonatomic,assign) CGFloat butWidth;//
  11. @end
  12. @implementation uploadFileRecordheadView
  13. - (id)initWithFrame:(CGRect)frame{
  14. self = [super initWithFrame:frame];
  15. [self drawAnyView];
  16. return self;
  17. }
  18. - (void)drawAnyView{
  19. [self setBackgroundColor:[UIColor hwColor:@"#F9F9F9" alpha:1.0]];
  20. self.layer.cornerRadius = 8;
  21. NSString *leftStr = NSLocalizedString(@"my_set_no_File_upload",nil);
  22. NSString *midStr = NSLocalizedString(@"my_set_no_File_download",nil);
  23. NSString *rightStr = NSLocalizedString(@"my_set_no_File_backups",nil);
  24. NSArray *titleArr = @[leftStr,midStr,rightStr];
  25. _butWidth = (SCREEN_W - 30)/3.0;
  26. NSString *languageCode = [NSLocale preferredLanguages][0];
  27. CGFloat fontSize = 14.0;
  28. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  29. {
  30. fontSize = 8;
  31. }
  32. for (NSInteger i=0; i<titleArr.count; i++) {
  33. NSString* title = titleArr[i];
  34. UIButton *but = [[UIButton alloc] init];
  35. but.tag = i+1;
  36. [but setTitle:title forState:UIControlStateNormal];
  37. [but setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal];
  38. [but setTitleColor:[UIColor hwColor:@"#0A132B" alpha:1.0] forState:UIControlStateSelected];
  39. but.titleLabel.font = [UIFont systemFontOfSize:fontSize];
  40. [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  41. [self addSubview:but];
  42. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.left.mas_equalTo(i*_butWidth);
  44. make.width.mas_equalTo(_butWidth);
  45. make.top.mas_equalTo(0);
  46. make.bottom.mas_equalTo(0);
  47. }];
  48. if(i==0){
  49. but.selected = YES;
  50. _selectBgView = [[UIView alloc] init];
  51. _selectBgView.backgroundColor = [UIColor whiteColor];
  52. _selectBgView.layer.cornerRadius = 8;
  53. [self insertSubview:_selectBgView atIndex:0];
  54. [_selectBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(10);
  56. make.width.mas_equalTo(_butWidth -20);
  57. make.top.mas_equalTo(6);
  58. make.bottom.mas_equalTo(-6);
  59. }];
  60. }
  61. }
  62. }
  63. #pragma mark 按钮点击
  64. - (void)didClickButFun:(UIButton*)but
  65. {
  66. NSInteger tag = but.tag;
  67. self.selectIndex = tag;
  68. if(_didClickButFun){
  69. _didClickButFun(tag);
  70. }
  71. }
  72. - (void)setSelectIndex:(NSInteger)selectIndex
  73. {
  74. _selectIndex = selectIndex;
  75. NSArray *subViews = [self subviews];
  76. for (UIButton *but in subViews) {
  77. if([but isKindOfClass:[UIButton class]]){
  78. if(but.tag == selectIndex){
  79. but.selected = YES;
  80. }
  81. else{
  82. but.selected = NO;
  83. }
  84. }
  85. }
  86. CGRect frame = _selectBgView.frame;
  87. frame.origin.x = (_selectIndex -1)* _butWidth + 10;
  88. [UIView animateWithDuration:0.2 animations:^{
  89. self->_selectBgView.frame = frame;
  90. }];
  91. }
  92. @end