uitextfielddelegate

Enabling done button after inserting one char in a textfield: textFieldDidEndEditing: or textFieldShouldBeginEditing: or?

☆樱花仙子☆ 提交于 2019-11-30 02:05:56
I would like to enable the done button on the navbar (in a modal view) when the user writes at least a char in a uitextfield. I tried: textFieldDidEndEditing: enables the button when the previous uitextfield resigns first responder (so with the zero chars in the current uitextfield). textFieldShouldBeginEditing: is called when the textfield becomes the first responder. Is there another way to do this? [EDIT] The solution could be -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string but neither [self.navigationItem

iOS Swift Pass Closure as Property?

爱⌒轻易说出口 提交于 2019-11-30 01:55:04
Let's say I have a custom UIView, lets call it MyCustomView. Inside this view is a UITextField property. Suppose my goal is to be able to create an instance of MyCustomView and add it to some view controller somewhere, and I want that view controller to be able to handle actions taken on that text field. For example, if I hit "return" on the keyboard within the text field, I may want to do some action - let me give an example of what I'm envisioning with some objective-c psuedo code: MyCustomView *myView = [[MyCustomView alloc] initWithFrame:CGRectMake(10,10,100,100)]; myView.textField

Change custom text field background color and text color IOS Swift

心已入冬 提交于 2019-11-30 01:49:04
问题 I'm using following custom text field class to change appearance of the text field. Now I need to change text field's background color, text color and place holder color, when user start editing and end editing the text field. How to do it, using this class. import Foundation import UIKit class CustomTextField: UITextField{ required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) //Border self.layer.cornerRadius = 15.0; self.layer.borderWidth = 1.5 self.layer.borderColor = UIColor

Action of the “Go” button of the ios keyboard

折月煮酒 提交于 2019-11-30 01:03:24
How do I bind an action to the Go button of the keyboard in iOS ? Mick MacCallum Objective-C Assuming you're using a UITextField, you could use the <UITextFieldDelegate> method textFieldShouldReturn . - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; // Dismiss the keyboard. // Execute any additional code return YES; } Don't forget to assign the class you put this code in as the text field's delegate. self.someTextField.delegate = self; Or if you'd prefer to use UIControlEvents, you can do the following [someTextField addTarget:self action:@selector

How shouldChangeCharactersInRange works in Swift?

倖福魔咒の 提交于 2019-11-29 21:17:55
I'm using shouldChangeCharactersInRange as a way of using on-the-fly type search. However I'm having a problem, shouldChangeCharactersInRange gets called before the text field actually updates: In Objective C, I solved this using using below: -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string]; return YES; } However, I've tried writing this in Swift: func textField(textField: UITextField!, shouldChangeCharactersInRange

iOS 6 UITextField Secure - How to detect backspace clearing all characters?

大兔子大兔子 提交于 2019-11-29 17:37:24
问题 In iOS 6 if you type text into a secure text field, change to another text field, then come back to the secure text field and hit backspace, all of the characters are removed. I am fine with this happening, however, I am trying to enable/disable a button based on if this secure text field has characters in it or not. I know how to determine what characters are in the fields and if a backspace is hit but I am having trouble determining how to detect if clearing of all the characters is

How to detect when user used Password AutoFill on a UITextField

独自空忆成欢 提交于 2019-11-29 06:53:38
I've implemented all the app and server changes necessary to support Password Autofill on iOS 11, and it works well. I'd like it to work a little better. My username and password fields are UITextFields. I would like to identify when a user has "autofilled" one of the two UITextFields, so I can progress to the next step. Currently the user autofills an item, then needs to press the "Next" button on the on-screen keyboard in order to advance. I'd like to trigger this on behalf of the user. The WWDC2017 Password Autofill session says to use UITextFieldTextDidChange. This works, but of course

Move view when so that keyboard does not hide text field

我的未来我决定 提交于 2019-11-29 00:33:40
In my app, when I click on a text field, the keyboard hides it. Please help me -- how can I move my view up when I click on the text field. I'm using this code in textFieldDidBeginEditing: self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 216, 0); self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 216, 0); but it doesn't work. You can do the following, but first make sure you've set the UITextField delegate to your self and #define kOFFSET_FOR_KEYBOARD 350; at the top. This is how far you want the view to be shifted //method to move the view up/down whenever the keyboard is shown

How to move cursor from one text field to another automatically in swift ios programmatically?

旧时模样 提交于 2019-11-28 23:11:45
问题 func textFieldDidBeginEditing(textField: UITextField) { scrlView.setContentOffset(CGPointMake(0, textField.frame.origin.y-70), animated: true) if(textField == firstDigit){ textField.becomeFirstResponder() secondDigit.resignFirstResponder() } else if(textField == secondDigit){ textField.becomeFirstResponder() thirdDigit.resignFirstResponder() } else if(textField == thirdDigit){ //textField.becomeFirstResponder() fourthDigit.becomeFirstResponder() } I am using four textfields for OTP entry in

Properly Subclassing UITextField in swift

二次信任 提交于 2019-11-28 18:56:05
So i have these textfields that i realised that they all have same properties, so i created new class called " UserInputs " and extended from UITextField , everything works properly except one thing, UITextFieldDelegate functions doesn't work, i mean when i focus on them it doesn't work, i want to add it in code because when you focus on my input fields they change border, how do i properly subclass from UITextField the only problems that i have are that functions: textFieldDidBeginEditing textFieldDidEndEditing and so doesn't work. this is my class where everything happens: import Foundation