JXDeviceLockVC.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // JXDeviceLockVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/4/2.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXDeviceLockVC.h"
  9. #import "NumLockViewController.h"
  10. #define HEIGHT 50
  11. #define IMGSIZE 170
  12. #define TAG_LABEL 1999
  13. @interface JXDeviceLockVC ()<NumLockViewControllerDelegate>
  14. @property (nonatomic, strong) UISwitch *setSwitch;
  15. @property (nonatomic, assign) BOOL isSetSwitch;
  16. @property (nonatomic, strong) JXImageView *setIV;
  17. @property (nonatomic, strong) NumLockViewController * numLockVC;
  18. @end
  19. @implementation JXDeviceLockVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.heightHeader = JX_SCREEN_TOP;
  24. self.heightFooter = 0;
  25. self.isGotoBack = YES;
  26. //self.view.frame = g_window.bounds;
  27. [self createHeadAndFoot];
  28. self.title = Localized(@"JX_EquipmentLock");
  29. int y = 0;
  30. JXImageView *iv = [self createButton:Localized(@"JX_Unlocking") drawTop:NO drawBottom:YES must:NO click:@selector(switchAction:) ParentView:self.tableBody];
  31. iv.frame = CGRectMake(0, y, JX_SCREEN_WIDTH, HEIGHT);
  32. y+=iv.frame.size.height;
  33. _setIV = [self createButton:Localized(@"JX_SetDeviceLockPassword") drawTop:NO drawBottom:YES must:NO click:@selector(setDeviceLockPassWord) ParentView:self.tableBody];
  34. _setIV.frame = CGRectMake(0, y, JX_SCREEN_WIDTH, HEIGHT);
  35. y+=_setIV.frame.size.height;
  36. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  37. if (str.length > 0) {
  38. _setIV.hidden = NO;
  39. }else {
  40. _setIV.hidden = YES;
  41. }
  42. }
  43. - (void)setDeviceLockPassWord {
  44. _numLockVC = [[NumLockViewController alloc]init];
  45. _numLockVC.delegate = self;
  46. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  47. if (str.length > 0) {
  48. self.isSetSwitch = NO;
  49. }else {
  50. self.isSetSwitch = YES;
  51. }
  52. _numLockVC.isSet = YES;
  53. // [self presentViewController:_numLockVC animated:YES completion:nil];
  54. [g_window addSubview:_numLockVC.view];
  55. }
  56. - (void)numLockVCSetSuccess:(NumLockViewController *)numLockVC {
  57. if (self.isSetSwitch) {
  58. [_setSwitch setOn:!_setSwitch.on];
  59. if (!_setSwitch.on) {
  60. [g_default removeObjectForKey:kDeviceLockPassWord];
  61. }
  62. }
  63. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  64. if (str.length > 0) {
  65. _setIV.hidden = NO;
  66. }else {
  67. _setIV.hidden = YES;
  68. }
  69. }
  70. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom must:(BOOL)must click:(SEL)click ParentView:(UIView *)parent{
  71. JXImageView* btn = [[JXImageView alloc] init];
  72. btn.backgroundColor = [UIColor whiteColor];
  73. btn.userInteractionEnabled = YES;
  74. if(click)
  75. btn.didTouch = click;
  76. else
  77. btn.didTouch = @selector(hideKeyboard);
  78. btn.delegate = self;
  79. [parent addSubview:btn];
  80. // [btn release];
  81. if(must){
  82. UILabel* p = [[UILabel alloc] initWithFrame:CGRectMake(INSETS, 5, 20, HEIGHT-5)];
  83. p.text = @"*";
  84. p.font = g_factory.font18;
  85. p.backgroundColor = [UIColor clearColor];
  86. p.textColor = [UIColor redColor];
  87. p.textAlignment = NSTextAlignmentCenter;
  88. [btn addSubview:p];
  89. // [p release];
  90. }
  91. //前面的说明label
  92. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(20, 0, 200, HEIGHT)];
  93. p.text = title;
  94. p.font = g_factory.font15;
  95. p.backgroundColor = [UIColor clearColor];
  96. p.textColor = [UIColor blackColor];
  97. p.tag = TAG_LABEL;
  98. [btn addSubview:p];
  99. // [p release];
  100. //分割线
  101. if(drawTop){
  102. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-30,LINE_WH)];
  103. line.backgroundColor = THE_LINE_COLOR;
  104. [btn addSubview:line];
  105. // [line release];
  106. }
  107. if(drawBottom){
  108. UIView* line = [[UIView alloc]initWithFrame:CGRectMake(15,HEIGHT-LINE_WH,JX_SCREEN_WIDTH-30,LINE_WH)];
  109. line.backgroundColor = THE_LINE_COLOR;
  110. [btn addSubview:line];
  111. // [line release];
  112. }
  113. //这个选择器仅用于判断,之后会修改为不可点击
  114. SEL check = @selector(switchAction:);
  115. //创建switch
  116. if(click == check){
  117. UISwitch * switchView = [[UISwitch alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH-INSETS-51, 6, 20, 20)];
  118. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  119. if (str.length > 0) {
  120. [switchView setOn:YES];
  121. }else {
  122. [switchView setOn:NO];
  123. }
  124. switchView.onTintColor = THEMECOLOR;
  125. [switchView addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
  126. [btn addSubview:switchView];
  127. _setSwitch = switchView;
  128. //取消调用switchAction
  129. btn.didTouch = nil;
  130. }else if(click){
  131. btn.frame = CGRectMake(btn.frame.origin.x -20, btn.frame.origin.y, btn.frame.size.width, btn.frame.size.height);
  132. UIImageView* iv;
  133. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  134. iv.image = [UIImage imageNamed:@"new_icon_>"];
  135. [btn addSubview:iv];
  136. // [iv release];
  137. }
  138. return btn;
  139. }
  140. -(void)switchAction:(id) sender {
  141. if (_setSwitch.on) {
  142. [_setSwitch setOn:NO];
  143. }else {
  144. [_setSwitch setOn:YES];
  145. }
  146. _numLockVC = [[NumLockViewController alloc]init];
  147. _numLockVC.delegate = self;
  148. _numLockVC.isClose = _setSwitch.on;
  149. // [self presentViewController:_numLockVC animated:YES completion:nil];
  150. [g_window addSubview:_numLockVC.view];
  151. self.isSetSwitch = YES;
  152. }
  153. /*
  154. #pragma mark - Navigation
  155. // In a storyboard-based application, you will often want to do a little preparation before navigation
  156. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  157. // Get the new view controller using [segue destinationViewController].
  158. // Pass the selected object to the new view controller.
  159. }
  160. */
  161. @end