ios - 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];
above coding , type amount in uialertview. when keyboard showing up, client want "done" button instead of "return". please me how it?
try this
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()
the other type of enum as
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 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 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];
Comments
Post a Comment