BlackDoorManager.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 = BDM_SCREEN_HEIGHT - 100;
  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. [view addSubview:button];
  48. button.alpha = 0.1;
  49. [button setTitle:serverNames[serverType] forState:UIControlStateNormal];
  50. [button setBackgroundColor:[UIColor greenColor]];
  51. [button setFrame:CGRectMake(15, 70, view.frame.size.width-30, 100)];
  52. }
  53. - (void)addTypeButtons:(UIView*)view {
  54. //当前服务器//
  55. NSInteger serverType = [ServerManager getServerType];
  56. NSArray* serverNames = [ServerManager getServerTypeNames];
  57. for (NSInteger i = 0; i <= 2; i++) {
  58. UIButton* button = [[UIButton alloc] init];
  59. button.tag = i;
  60. button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
  61. [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  62. [button addTarget:self action:@selector(serverButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  63. [view addSubview:button];
  64. //如果是当前服务器//
  65. button.alpha = serverType != i ? 1:0.1;
  66. if (i == 0) {
  67. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  68. [button setBackgroundColor:[UIColor greenColor]];
  69. [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 210, 200, 70)];
  70. }
  71. else if (i == 1) {
  72. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  73. [button setBackgroundColor:[UIColor magentaColor]];
  74. [button setFrame:CGRectMake(20, 300, 150, 70)];
  75. }
  76. else if (i == 2) {
  77. [button setTitle:serverNames[i] forState:UIControlStateNormal];
  78. [button setBackgroundColor:[UIColor redColor]];
  79. [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 300, 150, 70)];
  80. }
  81. }
  82. }
  83. //log
  84. - (void)addLogButton:(UIView*)view {
  85. CGFloat height = 100;
  86. UIView* logView = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-height, view.frame.size.width, height)];
  87. [logView setBackgroundColor:[UIColor clearColor]];
  88. [view addSubview:logView];
  89. //底部 log view
  90. UIView* dri = [[UIView alloc] initWithFrame:CGRectMake(0, 0, logView.frame.size.width, 0.5)];
  91. [dri setBackgroundColor:[UIColor lightGrayColor]];
  92. [logView addSubview:dri];
  93. UILabel* logText = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 30)];
  94. [logText setText:@"屏幕上显示日志"];
  95. [logText setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightBold]];
  96. [logView addSubview:logText];
  97. NSInteger logStatus = [BlackDoorManager getLogStatus];
  98. UISwitch* switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake((logView.frame.size.width - 50 - 20), 0, 50, 30)];
  99. [switchBtn setOn:logStatus == 1];
  100. [switchBtn addTarget:self action:@selector(clickSwitchButton:) forControlEvents:UIControlEventValueChanged];
  101. [logView addSubview:switchBtn];
  102. }
  103. - (void)backButtonClick:(id)sender {
  104. [self removeFromSuperview];
  105. }
  106. - (void)serverButtonClick:(UIButton*)button {
  107. [EasyTextView showSuccessText:@"切换服务器成功!"];
  108. [ServerManager setServerType:button.tag];
  109. [self removeFromSuperview];
  110. }
  111. - (void)clickSwitchButton:(id)sender {
  112. UISwitch* switchBtn = (UISwitch*)sender;
  113. [BlackDoorManager setLogStatus:switchBtn.isOn ? 1 : 0];
  114. [WindowLoggerManager refreshWindowLoggerStatus];
  115. }
  116. @end