在 iOS6 以前,會使用以下方法來顯示輸入框:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter
Password" message:@"" delegate:self cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setSecureTextEntry:YES]; //輸入內容為密碼
[alert addSubview:myTextField];
[myTextField release];
但在 iOS7 以後,addSubview 函式不支援了,要改統一使用以下方法:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter Password" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; //輸入內容為密碼
UITextField *myTextField = [alertView textFieldAtIndex:0];
[alertView show];
沒有留言:
張貼留言