如何在 UIAlertViewStylePlainTextInput Xcode 中将 return 按钮更改为完成
How to change return button to Done in UIAlertViewStylePlainTextInput Xcode
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_NAME
message:@"Please enter amount"
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 2;
[alert show];
以上是我在 UIAlertView 中的编码和输入数量。当键盘出现时,我的客户想要 "Done" 按钮而不是 "Return"。请帮我看看怎么做?
试试这个
UIAlertview
Objective-C
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: APP_NAME message:@"Please enter amount" delegate:self cancelButtonTitle:@"Done" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
[alert show];
Swift
var alert: UIAlertView = UIAlertView(title: APP_NAME, message: "Please enter amount", delegate: self, cancelButtonTitle: "Done", otherButtonTitles: "")
alert.alertViewStyle = .PlainTextInput
var textField: UITextField = alert.textFieldAtIndex(0)
textField.keyboardType = .NumberPad
textField.returnKeyType = UIReturnKeyDone
alert.show()
另一种类型的枚举为
typedef NS_ENUM(NSInteger, UIReturnKeyType) {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
};
note - UIAlertView has been deprecated since iOS 8 in this place use UIAlertcontroller
UIAlertController
Swift
var loginTextField: UITextField?
let alertController = UIAlertController(title:APP_NAME, message: "Please enter amount", preferredStyle: .Alert)
let ok = UIAlertAction(title: "Done", style: .Default, handler: { (action) -> Void in
print("Ok Button Pressed")
})
alertController.addAction(ok)
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
// Enter the textfiled customization code here.
loginTextField = textField
//loginTextField?.placeholder = "xxx"
loginTextField?.keyboardType = UIKeyboardType.NumberPad
loginTextField?.returnKeyType = UIReturnKey.Done
}
presentViewController(alertController, animated: true, completion: nil)
Objective-C
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:APP_NAME
message:@"Please enter amount"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *Done = [UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// handler code
}];
[alertController addAction:Done];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
}];
[self presentViewController:alertController animated:YES completion:nil];
试试这个,在属性检查器中,将 Return 键更改为“完成”
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_NAME
message:@"Please enter amount"
delegate:self
cancelButtonTitle:@"Done"
otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 2;
[alert show];
以上是我在 UIAlertView 中的编码和输入数量。当键盘出现时,我的客户想要 "Done" 按钮而不是 "Return"。请帮我看看怎么做?
试试这个
UIAlertview
Objective-C
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: APP_NAME message:@"Please enter amount" delegate:self cancelButtonTitle:@"Done" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField *textField = [alert textFieldAtIndex:0];
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
[alert show];
Swift
var alert: UIAlertView = UIAlertView(title: APP_NAME, message: "Please enter amount", delegate: self, cancelButtonTitle: "Done", otherButtonTitles: "")
alert.alertViewStyle = .PlainTextInput
var textField: UITextField = alert.textFieldAtIndex(0)
textField.keyboardType = .NumberPad
textField.returnKeyType = UIReturnKeyDone
alert.show()
另一种类型的枚举为
typedef NS_ENUM(NSInteger, UIReturnKeyType) {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
};
note - UIAlertView has been deprecated since iOS 8 in this place use
UIAlertcontroller
UIAlertController
Swift
var loginTextField: UITextField?
let alertController = UIAlertController(title:APP_NAME, message: "Please enter amount", preferredStyle: .Alert)
let ok = UIAlertAction(title: "Done", style: .Default, handler: { (action) -> Void in
print("Ok Button Pressed")
})
alertController.addAction(ok)
alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
// Enter the textfiled customization code here.
loginTextField = textField
//loginTextField?.placeholder = "xxx"
loginTextField?.keyboardType = UIKeyboardType.NumberPad
loginTextField?.returnKeyType = UIReturnKey.Done
}
presentViewController(alertController, animated: true, completion: nil)
Objective-C
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:APP_NAME
message:@"Please enter amount"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *Done = [UIAlertAction actionWithTitle:@"Done"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// handler code
}];
[alertController addAction:Done];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {
//handler code
textField.keyboardType = UIKeyboardTypeNumberPad;
// set return key type of current textfield
textField.returnKeyType = UIReturnKeyDone;
}];
[self presentViewController:alertController animated:YES completion:nil];
试试这个,在属性检查器中,将 Return 键更改为“完成”