[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]; } }
相关推荐
guangmingsky 2020-07-27
坚持着执着 2020-07-16
delmarks 2020-06-07
niehanmin 2020-05-28
ITstudied 2020-05-17
chenjinlong 2020-05-16
Richardxx 2020-05-16
e度空间 2020-05-07
jianghero 2020-05-03
郴州小程序 2020-02-19
Feastaw 2020-01-18
haohong 2020-01-17
起点 2019-12-11
虫二在路上 2014-06-05
CaiKanXP 2019-10-25
82473264 2014-07-01
STPace 2014-11-10