APPLockerChangeController.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // APPLockerChangeController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/13.
  6. //
  7. #import "APPLockerChangeController.h"
  8. #import "AppLockPasswordController.h"
  9. #import "APPLocker.h"
  10. @interface APPLockerChangeController ()
  11. @property (nonatomic, strong) UISwitch * lockSwitch;
  12. @property (nonatomic, strong) UILabel * switchTitle;
  13. @property (nonatomic, strong) UIButton * changePwdBtn;
  14. @end
  15. @implementation APPLockerChangeController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self configUI];
  19. }
  20. - (void)configUI{
  21. [self setNavigationTitle:NSLocalizedString(@"userCenter-yingysm", @"")];
  22. // 设置导航栏背景色
  23. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  24. // 设置标题颜色和字体
  25. [self setNavigationTitleColor:[UIColor whiteColor] font:[UIFont boldSystemFontOfSize:16]];
  26. // 设置返回按钮
  27. [self setBackButtonTitle:@""];
  28. [self setBackButtonColor:[UIColor whiteColor]];
  29. UIImageView * bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  30. [self.view addSubview:bgImageView];
  31. [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.left.right.top.bottom.mas_equalTo(0);
  33. }];
  34. [self.view addSubview:self.switchTitle];
  35. [self.view addSubview:self.lockSwitch];
  36. [self.view addSubview:self.changePwdBtn];
  37. [self.switchTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.height.mas_equalTo(16);
  39. make.left.mas_equalTo(30);
  40. make.top.mas_equalTo(SCREEN_TOP+48);
  41. }];
  42. [self.lockSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.right.mas_equalTo(-30);
  44. make.centerY.mas_equalTo(self.switchTitle.mas_centerY);
  45. }];
  46. [self.changePwdBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.height.mas_equalTo(50);
  48. make.left.mas_equalTo(30);
  49. make.right.mas_equalTo(-30);
  50. make.top.mas_equalTo(self.switchTitle.mas_bottom).offset(40);
  51. }];
  52. self.lockSwitch.on = [APPLocker.sharedLocker isLockEnabled];
  53. }
  54. #pragma mark event
  55. - (void)changePwdButtonClicked{
  56. AppLockPasswordController * lockVc = [[AppLockPasswordController alloc] init];
  57. lockVc.mode = LockViewModeChange;
  58. UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:lockVc];
  59. navi.modalPresentationStyle = UIModalPresentationFullScreen;
  60. [self presentViewController:navi animated:YES completion:nil];
  61. }
  62. - (void)lockSwitchValueChange{
  63. NSError *error = nil;
  64. APPLocker *locker = [APPLocker sharedLocker];
  65. if (self.lockSwitch.isOn) {
  66. // 启用密码锁
  67. NSLog(@"111111");
  68. if (![locker enableLockWithError:&error]) {
  69. NSLog(@"启用失败: %@", error.localizedDescription);
  70. }
  71. }else{
  72. NSLog(@"2222");
  73. // 禁用密码锁
  74. if (![locker disableLockWithError:&error]) {
  75. NSLog(@"禁用失败: %@", error.localizedDescription);
  76. }
  77. }
  78. }
  79. #pragma mark lazy
  80. - (UISwitch *)lockSwitch{
  81. if (!_lockSwitch) {
  82. _lockSwitch = [[UISwitch alloc] init];
  83. _lockSwitch.onTintColor = globalColor(GCTypeGreen);
  84. _lockSwitch.thumbTintColor = UIColor.whiteColor;
  85. [_lockSwitch addTarget:self action:@selector(lockSwitchValueChange) forControlEvents:UIControlEventValueChanged];
  86. }
  87. return _lockSwitch;
  88. }
  89. - (UILabel *)switchTitle{
  90. if (!_switchTitle) {
  91. _switchTitle = [[UILabel alloc] init];
  92. _switchTitle.textColor = UIColor.whiteColor;
  93. _switchTitle.text = NSLocalizedString(@"AppLock_switch", @"");
  94. _switchTitle.font = SYSFONT(16);
  95. }
  96. return _switchTitle;
  97. }
  98. - (UIButton *)changePwdBtn{
  99. if (!_changePwdBtn) {
  100. _changePwdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  101. [_changePwdBtn setBackgroundColor:globalColor(GCTypeGreen)];
  102. // [_changePwdBtn setBackgroundColor:[UIColor jk_colorWithHexString:@"#6E75FB"]];
  103. [_changePwdBtn setTitle:NSLocalizedString(@"userCenter-xiugaimm", @"") forState: UIControlStateNormal];
  104. [_changePwdBtn setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
  105. _changePwdBtn.titleLabel.font = SYSFONT(16);
  106. _changePwdBtn.layer.cornerRadius = 5.f;
  107. _changePwdBtn.layer.masksToBounds = YES;
  108. [_changePwdBtn addTarget:self action:@selector(changePwdButtonClicked) forControlEvents:UIControlEventTouchUpInside];
  109. }
  110. return _changePwdBtn;
  111. }
  112. #pragma mark statusBar
  113. - (UIStatusBarStyle)preferredStatusBarStyle{
  114. return UIStatusBarStyleLightContent;
  115. }
  116. @end