123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // BlackDoorManager.m
- // KidsWatchIOS
- //
- // Created by 振兴 刘 on 2019/11/22.
- // Copyright © 2019 All rights reserved.
- //
- #import "BlackDoorManager.h"
- #import "BlackDoorManager+data.h"
- #import <EasyShowView/EasyShowView.h>
- @implementation BlackDoorManager
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4]];
- UIView* view = [self addWhiteView];
- [self addBackButton:view];
- [self addCategoryButtons:view];
- [self addTypeButtons:view];
- [self addLogButton:view];
- }
- return self;
- }
- - (UIView*)addWhiteView {
- CGFloat Height = 450;
- UIView* view = [[UIView alloc] initWithFrame:CGRectMake(20, (BDM_SCREEN_HEIGHT-Height)/2, BDM_SCREEN_WIDTH - 40, Height)];
- [view setBackgroundColor:[UIColor whiteColor]];
- [self addSubview:view];
- return view;
- }
- //关闭
- - (void)addBackButton:(UIView*)view {
- UIButton* backBtn = [[UIButton alloc] init];
- [backBtn setTitle:@"关闭" forState:UIControlStateNormal];
- [backBtn setBackgroundColor:[UIColor redColor]];
- [backBtn setFrame:CGRectMake((view.frame.size.width - 60), 0, 60, 60)];
- [backBtn addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- [view addSubview:backBtn];
- }
- - (void)addCategoryButtons:(UIView*)view {
- //当前服务器//
- NSInteger serverType = [ServerManager getServerCategory];
- NSArray* serverNames = [ServerManager getServerCategoryNames];
-
- UIButton* button = [[UIButton alloc] init];
- button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
- [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- button.alpha = 0.1;
- [button setTitle:serverNames[serverType] forState:UIControlStateNormal];
- [button setBackgroundColor:[UIColor greenColor]];
- [button setFrame:CGRectMake(15, 70, view.frame.size.width-30, 100)];
- [view addSubview:button];
-
- UIView* dri = [[UIView alloc] initWithFrame:CGRectMake(0, button.frame.origin.y + button.frame.size.height + 20, view.frame.size.width, 0.5)];
- [dri setBackgroundColor:[UIColor lightGrayColor]];
- [view addSubview:dri];
- }
- - (void)addTypeButtons:(UIView*)view {
- //当前服务器//
- NSInteger serverType = [ServerManager getServerType];
- NSArray* serverNames = [ServerManager getServerTypeNames];
-
- for (NSInteger i = 0; i <= 2; i++) {
- UIButton* button = [[UIButton alloc] init];
- button.tag = i;
- button.titleLabel.lineBreakMode = 0;//这句话很重要,不加这句话加上换行符也没用
- [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(serverButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- [view addSubview:button];
-
- //如果是当前服务器//
- button.alpha = serverType != i ? 1:0.1;
-
- if (i == 0) {
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
- [button setBackgroundColor:[UIColor greenColor]];
- [button setFrame:CGRectMake((view.frame.size.width/2 - 200/2), 210, 200, 70)];
- }
- else if (i == 1) {
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
- [button setBackgroundColor:[UIColor magentaColor]];
- [button setFrame:CGRectMake(20, 300, 150, 70)];
- }
- else if (i == 2) {
- [button setTitle:serverNames[i] forState:UIControlStateNormal];
- [button setBackgroundColor:[UIColor orangeColor]];
- [button setFrame:CGRectMake(view.frame.size.width - 150 - 20, 300, 150, 70)];
- }
- }
- }
- //log
- - (void)addLogButton:(UIView*)view {
- CGFloat height = 50;
- UIView* logView = [[UIView alloc] initWithFrame:CGRectMake(0, view.frame.size.height-height, view.frame.size.width, height)];
- [logView setBackgroundColor:[UIColor clearColor]];
- [view addSubview:logView];
-
- //底部 log view
- UIView* dri = [[UIView alloc] initWithFrame:CGRectMake(0, 0, logView.frame.size.width, 0.5)];
- [dri setBackgroundColor:[UIColor lightGrayColor]];
- [logView addSubview:dri];
-
- UILabel* logText = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 200, 30)];
- [logText setText:@"屏幕上显示日志"];
- [logText setFont:[UIFont systemFontOfSize:17 weight:UIFontWeightBold]];
- [logView addSubview:logText];
-
- NSInteger logStatus = [BlackDoorManager getLogStatus];
- UISwitch* switchBtn = [[UISwitch alloc] initWithFrame:CGRectMake((logView.frame.size.width - 50 - 20), 10, 50, 30)];
- [switchBtn setOn:logStatus == 1];
- [switchBtn addTarget:self action:@selector(clickSwitchButton:) forControlEvents:UIControlEventValueChanged];
- [logView addSubview:switchBtn];
- }
- - (void)backButtonClick:(id)sender {
- [self removeFromSuperview];
- }
- - (void)serverButtonClick:(UIButton*)button {
- NSInteger type = button.tag;
- if (type == [ServerManager getServerType])
- return;
- [EasyTextView showSuccessText:@"切换服务器成功!"];
- [ServerManager setServerType:type];
- [self removeFromSuperview];
- }
- - (void)clickSwitchButton:(id)sender {
- UISwitch* switchBtn = (UISwitch*)sender;
- [BlackDoorManager setLogStatus:switchBtn.isOn ? 1 : 0];
- [WindowLoggerManager refreshWindowLoggerStatus];
- }
- @end
|