BlackDoorManager.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // BlackDoorManager.m
  3. // KidsWatchIOS
  4. //
  5. // Created by 振兴 刘 on 2019/11/22.
  6. // Copyright © 2019 All rights reserved.
  7. //
  8. #import "BlackDoorManager.h"
  9. #import "BlackDoorManager+data.h"
  10. #import <EasyShowView/EasyShowView.h>
  11. @implementation BlackDoorManager
  12. - (instancetype)initWithFrame:(CGRect)frame {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
  16. UIView* view = [self addWhiteView];
  17. [self addBackButton:view];
  18. [self addCategoryButtons:view];
  19. [self addTypeButtons:view];
  20. [self addLogButton:view];
  21. }
  22. return self;
  23. }
  24. - (UIView*)addWhiteView {
  25. CGFloat Height = 450;
  26. UIView* view = [[UIView alloc] initWithFrame:CGRectMake(20, (BDM_SCREEN_HEIGHT-Height)/2, BDM_SCREEN_WIDTH - 40, Height)];
  27. [view setBackgroundColor:[UIColor whiteColor]];
  28. [self addSubview:view];
  29. return view;
  30. }
  31. //关闭
  32. - (void)addBackButton:(UIView*)view {
  33. UIButton* backBtn = [[UIButton alloc] init];
  34. [backBtn setTitle:@"关闭" forState:UIControlStateNormal];
  35. [backBtn setBackgroundColor:[UIColor redColor]];
  36. [backBtn setFrame:CGRectMake((view.frame.size.width - 60), 0, 60, 60)];
  37. [backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  38. [view addSubview:backBtn];
  39. }
  40. - (void)addCategoryButtons:(UIView*)view {
  41. //当前服务器//
  42. NSInteger serverType = [ServerManager getServerCategory];
  43. NSArray* serverNames = [ServerManager getServerCategoryNames];
  44. UIButton* button = [[UIButton alloc] init];
  45. button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
  46. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  47. button.alpha = 0.1;
  48. [button setTitle:serverNames[serverType] forState:UIControlStateNormal];
  49. [button setBackgroundColor:[UIColor greenColor]];
  50. [button setFrame:CGRectMake(15, 70, view.frame.size.width-30, 100)];
  51. [view addSubview:button];
  52. UIView* dri = [[UIView alloc] initWithFrame:CGRectMake(0, button.frame.origin.y + button.frame.size.height + 20, view.frame.size.width, 0.5)];
  53. [dri setBackgroundColor:[UIColor lightGrayColor]];
  54. [view addSubview:dri];
  55. }
  56. - (void)addTypeButtons:(UIView*)view {
  57. //当前服务器//
  58. NSInteger serverType = [ServerManager getServerType];
  59. NSArray* serverNames = [ServerManager getServerTypeNames];
  60. for (NSInteger i = 0; i <= 2; i++) {
  61. UIButton* button = [[UIButton alloc] init];
  62. button.tag = i;
  63. button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
  64. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  65. [button addTarget:self action:@selector(serverButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  66. [view addSubview:button];
  67. //如果是当前服务器//
  68. button.alpha = serverType != i ? 1:0.1;
  69. if (i == 0) {
  70. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  71. [button setBackgroundColor:[UIColor greenColor]];
  72. [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 210, 200, 70)];
  73. }
  74. else if (i == 1) {
  75. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  76. [button setBackgroundColor:[UIColor magentaColor]];
  77. [button setFrame:CGRectMake(20, 300, 150, 70)];
  78. }
  79. else if (i == 2) {
  80. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  81. [button setBackgroundColor:[UIColor orangeColor]];
  82. [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 300, 150, 70)];
  83. }
  84. }
  85. }
  86. //log
  87. - (void)addLogButton:(UIView*)view {
  88. CGFloat height = 50;
  89. UIView* logView = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-height, view.frame.size.width, height)];
  90. [logView setBackgroundColor:[UIColor clearColor]];
  91. [view addSubview:logView];
  92. //底部 log view
  93. UIView* dri = [[UIView alloc] initWithFrame:CGRectMake(0, 0, logView.frame.size.width, 0.5)];
  94. [dri setBackgroundColor:[UIColor lightGrayColor]];
  95. [logView addSubview:dri];
  96. UILabel* logText = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 30)];
  97. [logText setText:@"屏幕上显示日志"];
  98. [logText setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightBold]];
  99. [logView addSubview:logText];
  100. NSInteger logStatus = [BlackDoorManager getLogStatus];
  101. UISwitch* switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake((logView.frame.size.width - 50 - 20), 10, 50, 30)];
  102. [switchBtn setOn:logStatus == 1];
  103. [switchBtn addTarget:self action:@selector(clickSwitchButton:) forControlEvents:UIControlEventValueChanged];
  104. [logView addSubview:switchBtn];
  105. }
  106. - (void)backButtonClick:(id)sender {
  107. [self removeFromSuperview];
  108. }
  109. - (void)serverButtonClick:(UIButton*)button {
  110. NSInteger type = button.tag;
  111. if (type == [ServerManager getServerType])
  112. return;
  113. [EasyTextView showSuccessText:@"切换服务器成功!"];
  114. [ServerManager setServerType:type];
  115. [self removeFromSuperview];
  116. }
  117. - (void)clickSwitchButton:(id)sender {
  118. UISwitch* switchBtn = (UISwitch*)sender;
  119. [BlackDoorManager setLogStatus:switchBtn.isOn ? 1 : 0];
  120. [WindowLoggerManager refreshWindowLoggerStatus];
  121. }
  122. @end