NASCommonUsedView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // NASCommonUsedView.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/6/19.
  6. //
  7. #import "NASCommonUsedView.h"
  8. @interface NASCommonUsedView ()
  9. @property(nonatomic,strong) UILabel*titleLabel;
  10. @end
  11. @implementation NASCommonUsedView
  12. - (id)initWithFrame:(CGRect)frame{
  13. self = [super initWithFrame:frame];
  14. //self.backgroundColor = [UIColor clearColor];
  15. [self drawAnyView];
  16. return self;
  17. }
  18. -(void)drawAnyView
  19. {
  20. UIView *whiteBgView = [[UIView alloc] init];
  21. whiteBgView.backgroundColor = [UIColor whiteColor];
  22. [self addSubview:whiteBgView];
  23. whiteBgView.layer.cornerRadius = 12;
  24. whiteBgView.layer.masksToBounds = YES;
  25. [whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.top.mas_equalTo(0);
  27. make.left.mas_equalTo(16);
  28. make.right.mas_equalTo(-16);
  29. make.bottom.mas_equalTo(0);
  30. }];
  31. _titleLabel = [[UILabel alloc] init];
  32. _titleLabel.font = [UIFont boldSystemFontOfSize:16.0];
  33. _titleLabel.textColor = [UIColor hwColor:@"#0A132B"];
  34. _titleLabel.text = NSLocalizedString(@"NAS_common_used",nil);
  35. [whiteBgView addSubview:_titleLabel];
  36. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.top.mas_equalTo(16);
  38. make.left.mas_equalTo(16);
  39. make.right.mas_equalTo(-24-12-10);
  40. make.height.mas_equalTo(20);
  41. }];
  42. NSArray *titleArr = @[NSLocalizedString(@"my_set_no_File_backups",nil),
  43. NSLocalizedString(@"set_file_Transfer_WWAN_title",nil),
  44. NSLocalizedString(@"my_set_no_share",nil)
  45. //,NSLocalizedString(@"my_set_no_share",nil)
  46. ];
  47. NSArray *imageArr = @[@"nas_backups_icon",
  48. @"nas_set_icon",
  49. @"nas_share_icon"
  50. //,@"nas_share_icon"
  51. ];
  52. CGFloat butTopY = 50.0;
  53. CGFloat imageWH = 32.0;
  54. CGFloat butHeight = imageWH +20 +5;
  55. CGFloat butWidth = 70.0;
  56. CGFloat butSpace = (SCREEN_W -16*2 - butWidth*4)/5.0;
  57. for (int i=0; i<titleArr.count; i++) {
  58. UIButton *but = [[UIButton alloc] init];
  59. but.tag = 10+i;
  60. [but addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  61. [whiteBgView addSubview:but];
  62. // but.backgroundColor = [UIColor greenColor];
  63. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(butSpace + (butWidth+butSpace)*(i%4));
  65. make.width.mas_equalTo(butWidth);
  66. make.height.mas_equalTo(butHeight);
  67. make.top.mas_equalTo(butTopY + (i/4)* (butHeight + 25) );
  68. }];
  69. UIImageView *imageV = [[UIImageView alloc] init];
  70. imageV.image = [UIImage imageNamed:imageArr[i]];
  71. // imageV.layer.cornerRadius = 10;
  72. // imageV.layer.masksToBounds = YES;
  73. [but addSubview:imageV];
  74. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.centerX.mas_equalTo(0);
  76. make.width.mas_equalTo(imageWH);
  77. make.height.mas_equalTo(imageWH);
  78. make.top.mas_equalTo(0);
  79. }];
  80. UILabel *textLabel = [[UILabel alloc] init];
  81. textLabel.textAlignment = NSTextAlignmentCenter;
  82. textLabel.font = [UIFont systemFontOfSize:14.0];
  83. textLabel.textColor = [UIColor hwColor:@"#0A132B"];
  84. textLabel.text = titleArr[i];
  85. [but addSubview:textLabel];
  86. //textLabel.backgroundColor = [UIColor redColor];
  87. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.centerX.mas_equalTo(0);
  89. make.width.mas_equalTo(butWidth);
  90. make.height.mas_equalTo(20);
  91. make.top.equalTo(imageV.mas_bottom).offset(5);
  92. }];
  93. }
  94. }
  95. #pragma mark 按钮事件
  96. - (void)didClickButtonFun:(UIButton*)but
  97. {
  98. NSInteger tag = but.tag;
  99. HLog(@"%ld",tag);
  100. if(_didClickButtonFun){
  101. _didClickButtonFun(tag);
  102. }
  103. }
  104. @end