uitextfield

Grey out return key programmatically

妖精的绣舞 提交于 2020-08-26 10:45:49
问题 I am looking to enable the return key of a UITextField keyboard if (and only if) the user inputs a valid email address. I have tried a solution that dates back from 2009 which uses the private method setReturnKeyEnabled . Unfortunately, this method does not seem to exist anymore: No known instance method for selector 'setReturnKeyEnabled:' How can I programmatically enable and disable the return key of a keyboard? 回答1: All the other solutions do not answer the question. OP wants to "gray" out

How to toggle a UITextField secure text entry (hide password) in Swift?

喜夏-厌秋 提交于 2020-07-31 06:18:49
问题 I currently have a UITextfield with an eye icon in it that when pressed is supposed to toggle the secure text entry on and off. I know you can check mark the "secure text entry" box in the attributes inspector but how to do it so it toggles whenever the icon is pressed? 回答1: Use this code, iconClick is bool variable, or you need other condition check it, var iconClick = true eye Action method: @IBAction func iconAction(sender: AnyObject) { if(iconClick == true) { passwordTF.secureTextEntry =

Add icon or image in UITextField on left / right in Swift 4

ⅰ亾dé卋堺 提交于 2020-07-17 12:25:57
问题 I have set up the left icon in UITextField . When I set text, it is over the left icon. I want to set text after the icon in the UITextField . I have used below code. let imageView = UIImageView(image: UIImage(named: strImgname)) imageView.frame = CGRect(x: 0, y: 0, width: imageView.image!.size.width , height: imageView.image!.size.height) let paddingView: UIView = UIView.init(frame: CGRect(x: 0, y: 0, width: 50, height: 30)) paddingView.addSubview(imageView) txtField.leftViewMode = .always

Add icon or image in UITextField on left / right in Swift 4

会有一股神秘感。 提交于 2020-07-17 12:23:50
问题 I have set up the left icon in UITextField . When I set text, it is over the left icon. I want to set text after the icon in the UITextField . I have used below code. let imageView = UIImageView(image: UIImage(named: strImgname)) imageView.frame = CGRect(x: 0, y: 0, width: imageView.image!.size.width , height: imageView.image!.size.height) let paddingView: UIView = UIView.init(frame: CGRect(x: 0, y: 0, width: 50, height: 30)) paddingView.addSubview(imageView) txtField.leftViewMode = .always

How do you disable a 3rd party keyboard in your iOS app

好久不见. 提交于 2020-06-25 18:36:25
问题 Can you disable 3rd party keyboards in iOS? If so, how? 回答1: Add this method to your UIApplicationDelegate -(BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier { if (extensionPointIdentifier == UIApplicationKeyboardExtensionPointIdentifier) { return NO; } return YES; } 回答2: Swift 5.1 Add to AppDelegate.Swift: func application(application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: String) ->

Shortcuts or autofill for contact info in UITextFields

孤街醉人 提交于 2020-06-25 08:45:24
问题 When I'm in Safari in iOS, and I hit a form that requires I enter name and address, I get shortcuts in the keyboard area. For example, here is the keyboard when the focus is in a first name field. I can tap "Robert" instead of typing a name. A similar thing happens for fields for last name, phone, email, zip code. Can I get a similar thing in a native iOS app, in a UITextField ? Is there a way to mark a field so that the keyboard will offer these shortcut suggestions? 回答1: You can turn on or

Single extension for UITextView and UITextField in Swift

☆樱花仙子☆ 提交于 2020-06-23 01:44:12
问题 I want to create a single extension for both UITextField and UITextView and add a below method to it: func addDoneButtonOnKeyboardWith(selector : Selector) { let keyBoardToolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 30)) let barButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: selector) let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) keyBoardToolBar.items = [flexibleSpace, barButtonItem]

Single extension for UITextView and UITextField in Swift

馋奶兔 提交于 2020-06-23 01:43:23
问题 I want to create a single extension for both UITextField and UITextView and add a below method to it: func addDoneButtonOnKeyboardWith(selector : Selector) { let keyBoardToolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 320, height: 30)) let barButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: selector) let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) keyBoardToolBar.items = [flexibleSpace, barButtonItem]