uploadFileRecordheadView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. NSString *fourStr = NSLocalizedString(@"my_set_no_File_receive_title",nil);
  25. NSArray *titleArr = @[leftStr,midStr,rightStr,fourStr];
  26. _butWidth = (SCREEN_W - 30)/titleArr.count;
  27. NSString *languageCode = [NSLocale preferredLanguages][0];
  28. CGFloat fontSize = 14.0;
  29. if([languageCode rangeOfString:@"ja-"].location != NSNotFound)
  30. {
  31. fontSize = 8;
  32. }
  33. for (NSInteger i=0; i<titleArr.count; i++) {
  34. NSString* title = titleArr[i];
  35. UIButton *but = [[UIButton alloc] init];
  36. but.tag = i+1;
  37. [but setTitle:title forState:UIControlStateNormal];
  38. [but setTitleColor:[UIColor hwColor:@"#666666" alpha:1.0] forState:UIControlStateNormal];
  39. [but setTitleColor:[UIColor hwColor:@"#0A132B" alpha:1.0] forState:UIControlStateSelected];
  40. but.titleLabel.font = [UIFont systemFontOfSize:fontSize];
  41. [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  42. [self addSubview:but];
  43. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.mas_equalTo(i*_butWidth);
  45. make.width.mas_equalTo(_butWidth);
  46. make.top.mas_equalTo(0);
  47. make.bottom.mas_equalTo(0);
  48. }];
  49. if(i==0){
  50. but.selected = YES;
  51. _selectBgView = [[UIView alloc] init];
  52. _selectBgView.backgroundColor = [UIColor whiteColor];
  53. _selectBgView.layer.cornerRadius = 8;
  54. [self insertSubview:_selectBgView atIndex:0];
  55. [_selectBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(10);
  57. make.width.mas_equalTo(_butWidth -20);
  58. make.top.mas_equalTo(6);
  59. make.bottom.mas_equalTo(-6);
  60. }];
  61. }
  62. }
  63. }
  64. #pragma mark 按钮点击
  65. - (void)didClickButFun:(UIButton*)but
  66. {
  67. NSInteger tag = but.tag;
  68. self.selectIndex = tag;
  69. if(_didClickButFun){
  70. _didClickButFun(tag);
  71. }
  72. }
  73. - (void)setSelectIndex:(NSInteger)selectIndex
  74. {
  75. _selectIndex = selectIndex;
  76. NSArray *subViews = [self subviews];
  77. for (UIButton *but in subViews) {
  78. if([but isKindOfClass:[UIButton class]]){
  79. if(but.tag == selectIndex){
  80. but.selected = YES;
  81. }
  82. else{
  83. but.selected = NO;
  84. }
  85. }
  86. }
  87. CGRect frame = _selectBgView.frame;
  88. frame.origin.x = (_selectIndex -1)* _butWidth + 10;
  89. [UIView animateWithDuration:0.2 animations:^{
  90. self->_selectBgView.frame = frame;
  91. }];
  92. }
  93. @end