uitextfield

UITextField begin dictation

霸气de小男生 提交于 2019-12-18 05:41:54
问题 I'd like to programmatically put my UITextField input into dictation mode, without requiring the user to bring up and select dictation from the keyboard. Searched the API documentation but can find no solution. Any ideas? 回答1: This is currently not possible on iOS. The only place where it is kind of possible is in an app using WatchKit. In WKInterfaceController you can actually use presentTextInputControllerWithSuggestions with nil as parameter which starts dictation input immediately. 回答2:

Custom Clear Button

坚强是说给别人听的谎言 提交于 2019-12-18 03:43:53
问题 I want to create custom clear button on UITextField, that is to use rightView and put image there, the problem is attaching the original clear button event to that custom rightView. In Objective-C i can do that this way: SEL clearButtonSelector = NSSelectorFromString(@"clearButton"); // Reference clearButton getter IMP clearButtonImplementation = [self methodForSelector:clearButtonSelector]; // Create function pointer that returns UIButton from implementation of method that contains

UITextField within UISearchBar in iOS 7

喜你入骨 提交于 2019-12-18 03:22:13
问题 I am trying to accomplish the same look of my UISearchBar with a TextField within it, as in my iOS 6 app. I have tried to code it in several ways and not yet been successful. The problem is, I am not able to change the TextField's frame in any way since iOS 7. The result is, my TextField takes all the space in the NavigationBar and overrides the UIBarButtonItem (menu button) to the right. See pictures below: iOS 6 code: This is how I coded it in iOS 6, where I could set the TextFields frame

UITextField set cursor to start text position

寵の児 提交于 2019-12-18 03:17:26
问题 I need to move cursor to start text position on set focus on the textfield. Is it possible tot do? 回答1: Set your view controller (or some other appropriate object) as the text field's delegate and implement the textFieldDidBeginEditing: method like this: - (void)textFieldDidBeginEditing:(UITextField *)textField { UITextPosition *beginning = [textField beginningOfDocument]; [textField setSelectedTextRange:[textField textRangeFromPosition:beginning toPosition:beginning]]; } Note that

iPhone Force Textbox Input to Upper Case

时间秒杀一切 提交于 2019-12-18 01:22:20
问题 How do I force characters input into a textbox on the iPhone to upper case? 回答1: Set autocapitalizationType to UITextAutocapitalizationTypeAllCharacters on the UITextField . See UITextInputTraits protocol (adopted by UITextField) for more details. 回答2: This solution is not fully satisfying. Even with the autocapitalizationType set to UITextAutocapitalizationTypeAllCharacters , the user can still press caps to release the caps lock. And the textField.text = [textField.text

UIColor return wrong values for dark mode colors

99封情书 提交于 2019-12-18 01:10:35
问题 I have a custom UITextField subclass which changes its border color when typing something in it. I'm listening for changes by calling self.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged) and then, in textFieldDidChange(_:) I'm doing: self.layer.borderColor = UIColor(named: "testColor")?.cgColor Where testColor is a color defined in Assets.xcassets with variants for light and dark mode. The issue is that UIColor(named: "testColor")?.cgColor seems to always

Filtering characters entered into a UITextField

穿精又带淫゛_ 提交于 2019-12-17 23:37:06
问题 I have a UITextField in my application. I'd like to restrict the set of characters that can be can be entered into the field to a set that I have defined. I could filter the characters entered into the field when the text is committed using the UITextFieldDelegate method: - (BOOL)textFieldShouldReturn:(UITextField*)textField However, this gives the user a false impression as although restricted characters are removed from the final value, they were still visibly entered into the text field

Toolbar with “Previous” and “Next” for Keyboard inputAccessoryView

那年仲夏 提交于 2019-12-17 22:23:25
问题 I've been trying to implement this toolbar, where only the 'Next' button is enabled when the top textField is the firstResponder and only the 'Previous' button is enabled when the bottom textField is the firstResponder. It kind of works, but what keeps happening is I need to tap the 'Previous'/'Next' buttons twice each time to enable/disable the opposing button. Am I missing something in the responder chain that's making this happen? Here's my code: - (void)viewDidLoad { [super viewDidLoad];

How can I change the height of UITextField in UIAlertController in Swift?

不羁岁月 提交于 2019-12-17 20:14:36
问题 I have added a UITextField in a UIAlertController . I want to change the height of the text field. I have tried this way: let alertController = UIAlertController(title: "Comments", message: "Write your comments here", preferredStyle: UIAlertControllerStyle.alert) alertController.addTextField { (textField : UITextField) -> Void in var frame: CGRect = textField.frame frame.size.height = 100 textField.frame = frame textField.placeholder = "comment" print(textField.frame.size.height) } let

UITextField minimum fontsize

陌路散爱 提交于 2019-12-17 20:03:23
问题 I'm using the property minimumFontSize textField.font = [UIFont boldSystemFontOfSize:17]; textField.textColor = [UIColor darkGrayColor]; textField.minimumFontSize = 10; textField.adjustsFontSizeToFitWidth = YES; But the text never goes to minimum font size of 10, it gets truncated, but if I change the current fontSize to 10, the whole text appears correctly. Am I using this property wrong? 回答1: As late as it is ... you were setting up your UITextField correctly, and adjustsFontSizeToFitWidth