uploadFileRecordheadView.m 3.2 KB

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