[IOS]如何设置弹出输入框,输入MAC并自动插入

网友投稿 772 2022-10-08

[IOS]如何设置弹出输入框,输入MAC并自动插入

[IOS]如何设置弹出输入框,输入MAC并自动插入

-(void)showInputMacAlert{ UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTableInBundle(Input_MAC_Black_List_Alert_Title, nil, [[LanguageTool getInstance] getLocaleBundle], @"") message:NSLocalizedStringFromTableInBundle(Input_MAC_Black_List_Alert_Content, nil, [[LanguageTool getInstance] getLocaleBundle], @"") preferredStyle:UIAlertControllerStyleAlert]; UIView *subView1 = alertControl.view.subviews[0]; UIView *subView2 = subView1.subviews[0]; UIView *subView3 = subView2.subviews[0]; UIView *subView4 = subView3.subviews[0]; UIView *subView5 = subView4.subviews[0]; //IOS12 has a more uiview in subView5.subviews UILabel *titleView = subView5.subviews[0]; UILabel *messageView = subView5.subviews[1]; if ([titleView isMemberOfClass:[UIView class]]) { titleView = subView5.subviews[1]; messageView = subView5.subviews[2]; } titleView.textAlignment = NSTextAlignmentLeft; messageView.textAlignment = NSTextAlignmentLeft; //定义第一个输入框; [alertControl addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { [textField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged]; }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(Confirm_Bt_Title, nil, [[LanguageTool getInstance] getLocaleBundle], @"") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { //获取第1个输入框; UITextField *macTextField = alertControl.textFields.firstObject; BOOL isValidMac = [Util isValidMac:macTextField.text]; if (isValidMac) { [self addDeviceToBlacklist:macTextField.text]; }else{ [MBProgressHUD showToast:self.view content:NSLocalizedStringFromTableInBundle(Mac_Invalid, nil, [[LanguageTool getInstance] getLocaleBundle], @"")]; }// NSLog(@"controller text field content:%@", _macInputTextField.text); }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTableInBundle(Cancel_Bt_Title, nil, [[LanguageTool getInstance] getLocaleBundle], @"") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; [alertControl addAction:cancelAction]; [alertControl addAction:okAction]; [self presentViewController:alertControl animated:YES completion:nil]; }#pragma mark - textfield delegate-(void)textFieldDidEditing:(UITextField*)textField{ NSMutableString *inputText = [textField.text mutableCopy]; NSLog(@"input text-1:%@",inputText); //Remove all ':' to caculate length NSString *tempString = [textField.text stringByReplacingOccurrencesOfString:@":" withString:@""]; if (tempString.length !=0 && tempString.length%2==0 && textField.text.length<17 && ![_inputMacContentLastString isEqualToString:@":"]) { [inputText appendString:@":"]; textField.text = inputText; } if (inputText.length > 0) { _inputMacContentLastString = [inputText substringFromIndex:inputText.length-1]; } }

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringCloud GateWay网关示例代码详解
下一篇:Nest.js- 构建 Node.js Web 应用程序的框架(nextjs和nestjs)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~