ChangeLogoViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. //
  2. // ChangeLogoViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by APPLE on 2023/8/18.
  6. //
  7. #import "ChangeLogoViewController.h"
  8. #import "LogoSelectView.h"
  9. #import "iPhone.h"
  10. #import "UITextfield+NLLimit.h"
  11. @interface ChangeLogoViewController ()<UITextFieldDelegate,LogoSelectViewDelegate>
  12. {
  13. LogoSelectView *logoSelectView;
  14. UITextField *pwdTextField;
  15. UITextField *pwdAgainTextField;
  16. UIButton *okBtn;
  17. }
  18. @end
  19. @implementation ChangeLogoViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self drawAnyView];
  24. }
  25. - (void)drawAnyView{
  26. [self.view setBackgroundColor:HWF5F7FAColor];
  27. [self.toolBar setHidden:YES];
  28. [self.navigationBar setHidden:YES];
  29. [self.navBarBGView setHidden:NO];
  30. [self.titleLabel setText:NSLocalizedString(@"my_set_no_change_login",nil)];
  31. logoSelectView = [[LogoSelectView alloc] init];
  32. logoSelectView.delegate = self;
  33. //logoSelectView.backgroundColor = [UIColor redColor];
  34. [self.view addSubview:logoSelectView];
  35. [logoSelectView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.height.mas_equalTo(256);
  37. make.left.mas_equalTo(0);
  38. make.right.mas_equalTo(0);
  39. make.top.equalTo(self.navBarBGView.mas_bottom);
  40. }];
  41. /*修改入口密码*/
  42. // UILabel *pwdLabel = [[UILabel alloc] init];
  43. // [pwdLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
  44. // [pwdLabel setTextColor:HW0A132BColor];
  45. // [pwdLabel setText:NSLocalizedString(@"logo_set_pwd_tips",nil)];
  46. //
  47. // [self.view addSubview:pwdLabel];
  48. // [pwdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  49. // make.top.equalTo(logoSelectView.mas_bottom).offset(24.f);
  50. // make.left.mas_equalTo(16.f);
  51. // make.right.mas_equalTo(-16.f);
  52. // make.height.mas_equalTo(20.f);
  53. // }];
  54. //
  55. // NSString *placeholderStr = NSLocalizedString(@"logo_input_pwd_tips",nil);
  56. // NSString *placeholderStr1 = NSLocalizedString(@"logo_input_pwd_again_tips",nil);
  57. // CGFloat fontSize = 13.f;
  58. // CGFloat textfontSize = 16.f;
  59. // CGFloat inputTextFieldH = 48.f;
  60. // NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
  61. // style.alignment = NSTextAlignmentLeft;
  62. //
  63. // NSAttributedString *attri = nil;
  64. // NSAttributedString *attri1 = nil;
  65. // NSString *verphone = [iPhone phoneVersion];
  66. //
  67. // if ([verphone isEqualToString:@"10.3.3"]){
  68. // attri = [[NSAttributedString alloc] initWithString:placeholderStr
  69. // attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  70. // NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  71. // NSBaselineOffsetAttributeName:[NSNumber numberWithFloat:-1.5],
  72. // NSParagraphStyleAttributeName:style}];
  73. // attri1 = [[NSAttributedString alloc] initWithString:placeholderStr1
  74. // attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  75. // NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  76. // NSBaselineOffsetAttributeName:[NSNumber numberWithFloat:-1.5],
  77. // NSParagraphStyleAttributeName:style}];
  78. // }else{
  79. // attri = [[NSAttributedString alloc] initWithString:placeholderStr
  80. // attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  81. // NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  82. // NSParagraphStyleAttributeName:style}];
  83. // attri1 = [[NSAttributedString alloc] initWithString:placeholderStr1
  84. // attributes:@{NSForegroundColorAttributeName:COLOR_PACEHOLDER,
  85. // NSFontAttributeName:[UIFont systemFontOfSize:fontSize],
  86. // NSBaselineOffsetAttributeName:[NSNumber numberWithFloat:-1.5],
  87. // NSParagraphStyleAttributeName:style}];
  88. // }
  89. //
  90. // pwdTextField = [[UITextField alloc] init];
  91. // pwdTextField.delegate = self;
  92. // [pwdTextField setNl_maxLength:4];
  93. // [pwdTextField setKeyboardType:(UIKeyboardTypeNumberPad)];
  94. // [self.view addSubview:pwdTextField];
  95. // [pwdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  96. // make.top.equalTo(pwdLabel.mas_bottom).offset(12.f);
  97. // make.left.mas_equalTo(16.f);
  98. // make.right.mas_equalTo(-16.f);
  99. // make.height.mas_equalTo(inputTextFieldH);
  100. // }];
  101. // pwdTextField.attributedPlaceholder = attri;
  102. // pwdTextField.layer.cornerRadius = 8.f;
  103. // [pwdTextField setFont:[UIFont systemFontOfSize:textfontSize]];
  104. // [pwdTextField setTextColor:HW0A132BColor];
  105. // [pwdTextField setBackgroundColor:[UIColor whiteColor]];
  106. // UIView *leftView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, 15, inputTextFieldH))];
  107. // [leftView setBackgroundColor:[UIColor clearColor]];
  108. // [pwdTextField setLeftView:leftView];
  109. // [pwdTextField setLeftViewMode:(UITextFieldViewModeAlways)];
  110. //
  111. // pwdAgainTextField = [[UITextField alloc] init];
  112. // pwdAgainTextField.delegate = self;
  113. // [pwdAgainTextField setNl_maxLength:4];
  114. // [pwdAgainTextField setKeyboardType:(UIKeyboardTypeNumberPad)];
  115. // [self.view addSubview:pwdAgainTextField];
  116. // [pwdAgainTextField mas_makeConstraints:^(MASConstraintMaker *make) {
  117. // make.top.equalTo(pwdTextField.mas_bottom).offset(15.f);
  118. // make.left.mas_equalTo(16.f);
  119. // make.right.mas_equalTo(-16.f);
  120. // make.height.mas_equalTo(inputTextFieldH);
  121. // }];
  122. // pwdAgainTextField.attributedPlaceholder = attri1;
  123. // pwdAgainTextField.layer.cornerRadius = 8.f;
  124. // [pwdAgainTextField setFont:[UIFont systemFontOfSize:textfontSize]];
  125. // [pwdAgainTextField setTextColor:HW0A132BColor];
  126. // [pwdAgainTextField setBackgroundColor:[UIColor whiteColor]];
  127. // UIView *leftView1 = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, 15, inputTextFieldH))];
  128. // [leftView1 setBackgroundColor:[UIColor clearColor]];
  129. // [pwdAgainTextField setLeftView:leftView1];
  130. // [pwdAgainTextField setLeftViewMode:(UITextFieldViewModeAlways)];
  131. //
  132. /*确认按钮*/
  133. okBtn = [[UIButton alloc] init];
  134. CGFloat okBtn_W = SCREEN_W - 2*16.f;
  135. // gradient
  136. CAGradientLayer *gl = [CAGradientLayer layer];
  137. gl.frame = CGRectMake(0,0,okBtn_W,48);
  138. gl.startPoint = CGPointMake(0, 0.5);
  139. gl.endPoint = CGPointMake(1, 0.5);
  140. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  141. gl.locations = @[@(0), @(1.0f)];
  142. okBtn.layer.cornerRadius = 8;
  143. okBtn.clipsToBounds = YES;
  144. [okBtn.layer addSublayer:gl];
  145. [okBtn setTitle:NSLocalizedString(@"other_confirm",nil) forState:(UIControlStateNormal)];
  146. [okBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  147. [okBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  148. [self.view addSubview:okBtn];
  149. [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  150. //make.top.equalTo(pwdAgainTextField.mas_bottom).offset(16.f);
  151. make.top.equalTo(logoSelectView.mas_bottom).offset(60.f);
  152. make.centerX.equalTo(self.view.mas_centerX);
  153. make.width.mas_equalTo(okBtn_W);
  154. make.height.mas_equalTo(48);
  155. }];
  156. [okBtn addTarget:self
  157. action:@selector(okBtnPressed)
  158. forControlEvents:(UIControlEventTouchUpInside)];
  159. [okBtn setEnabled:NO];
  160. [okBtn setAlpha:0.5];
  161. }
  162. /*
  163. #pragma mark - Navigation
  164. // In a storyboard-based application, you will often want to do a little preparation before navigation
  165. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  166. // Get the new view controller using [segue destinationViewController].
  167. // Pass the selected object to the new view controller.
  168. }
  169. */
  170. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  171. {
  172. if (textField == pwdAgainTextField || textField == pwdTextField)
  173. {
  174. /*特定字符限制*/
  175. NSCharacterSet *cs;
  176. cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"]invertedSet];
  177. NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs]componentsJoinedByString:@""];//按cs分离出数组,数组按@""分离出字符串
  178. BOOL canChange = [string isEqualToString:filtered];
  179. if (logoSelectView.selectIndex <= 0){
  180. if ([pwdAgainTextField.text isEqualToString:@""]
  181. || pwdAgainTextField.text == nil
  182. || [pwdTextField.text isEqualToString:@""]
  183. || pwdTextField.text == nil)
  184. {
  185. [okBtn setEnabled:NO];
  186. [okBtn setAlpha:0.5];
  187. }else{
  188. [okBtn setEnabled:YES];
  189. [okBtn setAlpha:1];
  190. }
  191. }
  192. return canChange;
  193. }
  194. return YES;
  195. }
  196. - (void)okBtnPressed{
  197. // if (pwdTextField.text.length > 0 || pwdAgainTextField.text.length > 0){
  198. // if (![pwdTextField.text isEqualToString:pwdAgainTextField.text] || pwdAgainTextField.text.length != 4 ){
  199. // [[iToast makeText:NSLocalizedString(@"logo_input_pwd_no_same_tips",nil)] show];
  200. // return;
  201. // }else{
  202. // /*设置密码*/
  203. // NSDictionary *deviceDict = [HWDataManager getObjectWithKey:Const_Have_Add_Device];
  204. // NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithDictionary:deviceDict];
  205. // [dict setObject:pwdAgainTextField.text forKey:Const_Have_Add_Device_PWD];
  206. // [HWDataManager setObjectWithKey:Const_Have_Add_Device value:dict];
  207. //
  208. // [[iToast makeText:NSLocalizedString(@"logo_set_pwd_success",nil)] show];
  209. // }
  210. // }
  211. // 获取Info.plist的路径
  212. // NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
  213. //
  214. // // 读取Info.plist文件
  215. // NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
  216. if (logoSelectView.selectIndex == 1){
  217. /*设置图标*/
  218. // [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon 1" completionHandler:^(NSError * _Nullable error) {
  219. // [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:1];
  220. // }];
  221. [iTools lc_setAlternateIconName:@"AppIconJSJ"];
  222. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:1];
  223. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Change_calculator_icon"];
  224. // 修改应用名称
  225. //[infoDict setObject:NSLocalizedString(@"logo_calculator",nil) forKey:@"CFBundleDisplayName"]; // 或者使用CFBundleName
  226. }else if (logoSelectView.selectIndex == 2){
  227. /*设置图标*/
  228. // [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon 2" completionHandler:^(NSError * _Nullable error) {
  229. // [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:2];
  230. // }];
  231. [iTools lc_setAlternateIconName:@"AppIconLlq"];
  232. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:2];
  233. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Change_browser_icon"];
  234. // 修改应用名称
  235. //[infoDict setObject:NSLocalizedString(@"logo_bowser",nil) forKey:@"CFBundleDisplayName"]; // 或者使用CFBundleName
  236. }
  237. else if (logoSelectView.selectIndex == 0){
  238. [iTools lc_setAlternateIconName:@"AppIcon1"];
  239. [HWDataManager setIntegerWithKey:Const_Mask_View_Model value:0];
  240. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Change_private_x_icon"];
  241. // 修改应用名称
  242. //[infoDict setObject:NSLocalizedString(@"logo_bowser",nil) forKey:@"CFBundleDisplayName"]; // 或者使用CFBundleName
  243. }
  244. // 保存修改后的Info.plist文件
  245. // [infoDict writeToFile:plistPath atomically:YES];
  246. //
  247. // // 刷新应用的名称
  248. // [[NSBundle mainBundle] load];
  249. //
  250. // infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
  251. //
  252. // NSString *DisplayName = [NSBundle mainBundle].infoDictionary[@"CFBundleDisplayName"];
  253. // HLog(@"CFBundleDisplayName:%@",DisplayName);
  254. //提示语
  255. [[iToast makeText:NSLocalizedString(@"logo_did_change_login",nil)] show];
  256. }
  257. - (void)logoSelectViewHaveSelect{
  258. [okBtn setEnabled:YES];
  259. [okBtn setAlpha:1];
  260. }
  261. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  262. [[UIApplication sharedApplication].keyWindow endEditing:YES];
  263. }
  264. - (NSString *)documentPathForAccount:(NSString *)account fileFolder:(NSString *)fileFolder {
  265. NSString *path = DocumentPath;
  266. if (account.length != 0) {
  267. path = [NSString stringWithFormat:@"%@/%@/",DocumentPath,account];
  268. }
  269. if ([fileFolder containsString:@"/"]) {
  270. NSString *path1 = [path stringByAppendingPathComponent:fileFolder];
  271. path1 = [path1 stringByDeletingLastPathComponent];
  272. NSError *error;
  273. if (![[NSFileManager defaultManager] fileExistsAtPath:path1]) {
  274. [[NSFileManager defaultManager] createDirectoryAtPath:path1 withIntermediateDirectories:YES attributes:nil error:&error];
  275. }
  276. }else{
  277. NSError *error;
  278. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  279. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error];
  280. }
  281. }
  282. return [path stringByAppendingPathComponent:fileFolder];
  283. }
  284. @end