NASCommonUsedView.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. NSArray *imageArr = @[@"nas_backups_icon",
  46. @"nas_set_icon",
  47. @"nas_share_icon"];
  48. CGFloat butTopY = 50.0;
  49. CGFloat butWidth = 32.0;
  50. CGFloat butHeight = 32.0 +20 +5;
  51. CGFloat leftSpace = 26.0;
  52. CGFloat butSpace = (SCREEN_W -16*2 -leftSpace*2 - butWidth*4)/3.0;
  53. CGFloat LabelWidth = 60.0;
  54. for (int i=0; i<titleArr.count; i++) {
  55. UIImageView *imageV = [[UIImageView alloc] init];
  56. imageV.image = [UIImage imageNamed:imageArr[i]];
  57. imageV.layer.cornerRadius = 10;
  58. imageV.layer.masksToBounds = YES;
  59. [whiteBgView addSubview:imageV];
  60. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  62. make.width.mas_equalTo(butWidth);
  63. make.height.mas_equalTo(butWidth);
  64. make.top.mas_equalTo(butTopY);
  65. }];
  66. UILabel *textLabel = [[UILabel alloc] init];
  67. textLabel.textAlignment = NSTextAlignmentCenter;
  68. textLabel.font = [UIFont systemFontOfSize:14.0];
  69. textLabel.textColor = [UIColor hwColor:@"#0A132B"];
  70. textLabel.text = titleArr[i];
  71. [whiteBgView addSubview:textLabel];
  72. //textLabel.backgroundColor = [UIColor redColor];
  73. [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i - (LabelWidth -butWidth)/2.0);
  75. make.width.mas_equalTo(LabelWidth);
  76. make.height.mas_equalTo(20);
  77. make.top.equalTo(imageV.mas_bottom).offset(5);
  78. }];
  79. UIButton *but = [[UIButton alloc] init];
  80. but.tag = 10+i;
  81. [but addTarget:self action:@selector(didClickButtonFun:) forControlEvents:UIControlEventTouchUpInside];
  82. [whiteBgView addSubview:but];
  83. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.left.mas_equalTo(leftSpace + (butWidth+butSpace)*i);
  85. make.width.mas_equalTo(butWidth);
  86. make.height.mas_equalTo(butHeight);
  87. make.top.mas_equalTo(butTopY);
  88. }];
  89. }
  90. }
  91. #pragma mark 按钮事件
  92. - (void)didClickButtonFun:(UIButton*)but
  93. {
  94. NSInteger tag = but.tag;
  95. HLog(@"%ld",tag);
  96. if(_didClickButtonFun){
  97. _didClickButtonFun(tag);
  98. }
  99. }
  100. @end