uitextfield

UITextField clear when selected, but also restore data if nothing is input

和自甴很熟 提交于 2019-12-14 01:30:18
问题 I have a table with UITextFields, and I want to make it so that when a textfield is selected, the current info is cleared (to allow new input), but if the user decides (after selecting) that they don't want to change it, I want them to be able to click elsewhere and the data from before reappears in the textfield. Is there an easy way to do this? 回答1: A good way to do this that's nice and user friendly is to use the placeholder property. Set up your viewController as the textfield's delegate

UITextField placeholder text: adjust to fit

我们两清 提交于 2019-12-14 00:17:08
问题 I have UITextField with longer text in it set as placeholder. What I want is for this placeholder text to adjust its font size when the width of field is too small. I already tried this solution described in other posts (programmatically and in IB) self.fieldTest.adjustsFontSizeToFitWidth = true self.fieldTest.minimumFontSize = 10.0 What am I missing here? 回答1: You can create a subclass of UITextField : class AutoSizeTextField: UITextField { override func layoutSubviews() { super

iOS Objective-C UITextField Date Formatting

﹥>﹥吖頭↗ 提交于 2019-12-13 22:26:56
问题 I'm trying to create a credit card processing view controller. I have a expiration date field that I would like to format as MM/YY on the fly. I tried to follow the snippet from here UITextField format in xx-xx-xxx, but it uses NSNumber when used on a expiration date that has a leading 0 it doesn't work. I searched google and nothing came up either. The leading zero is removed. How can I use a UITextField to format as MM/YY on the fly as the user is inputing (ex. 05/16)? It is possible

How to remove the outer border of UITextField presented in UIAlertActionController

末鹿安然 提交于 2019-12-13 22:17:20
问题 I am adding multiple UITextFields to my alert controller, and I don't want that ugly black box around them. I know it's not the border property of the textField, because I have tried setting that and that influences the actual textField, not the box. I have tried textField.superview?.backgroundColor = UIColor.redColor() textField.superview?.layer.borderColor = UIColor.redColor().CGColor Setting the background Color works as expected, filling in the space between the textfield and the "black

Set focus and show keyboard programmatically in xcode?

拥有回忆 提交于 2019-12-13 21:25:18
问题 Here is my coding that UITextField is programmatically created when click on UIButton. But to enhancement is I want to set focus (and show keyboard) to new UITextField when UITextField is being created. UITextField * txtComp=[[UITextField alloc]initWithFrame:CGRectMake(20,y, 450, 50)]; txtComp.borderStyle=UITextBorderStyleNone; txtComp.delegate = self; txtComp.tag=i+1; txtComp.section=index; txtComp.placeholder = @"New UITextField"; [txtComp becomeFirstResponder]; Above coding work as

uipopover hides when keyboard shows

天大地大妈咪最大 提交于 2019-12-13 21:08:24
问题 i have an UIpopover with UItextfield in it, when i open popover and tap on uitextfield then keyboard shows, but it hide the popover. How can i show keyboard without hiding UIpopover? i am calling popover in UIWebView because i use cordova 1.8.1, but i tried it in UIView too, and it hides too. here code of calling UIpopover : if (popEl==nil){ popEl=[[Popover alloc] init]; } if (pcs==nil){ pcs=[[UIPopoverController alloc] initWithContentViewController:popEl]; pcs.delegate=self; } [pcs

UITextField Custom Clear Button

久未见 提交于 2019-12-13 20:41:45
问题 I'm trying to implement custom clear button in text field using the solution on Custom Clear Button It doesn't work, it shows default clear button. Any idea why? Following is my code: class CustomTextField: UITextField { override init(frame: CGRect) { super.init(frame: frame) let clearButton = UIButton(frame: CGRect(x: 0, y: 0, width: 16, height: 16)) clearButton.setImage(UIImage(named: "Glyph/16x16/Clear")!, for: []) self.rightView = clearButton clearButton.addTarget(self, action: #selector

Textfield shouldChangeCharactersIn for password field clear

这一生的挚爱 提交于 2019-12-13 20:10:37
问题 I am using MVVM Structure and when textfield value changed update the view model. Everything working fine except password field Here is code func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { if let text = textField.text, let range = Range.init(range, in: text) { let newText = text.replacingCharacters(in: range, with: string) if textField == txtOldPassword { changePasswordViewModel.updateOldPassword(string: newText) }

iOS text field not resigning first responder

我只是一个虾纸丫 提交于 2019-12-13 19:07:41
问题 I can't seem to resign first responder for text field. Please help and I have looked at other solutions on stackoverflow but can't find the solution. Here is the error thrown unrecognized selector sent to instance class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet var textInputScreen: UITextField! override func viewDidLoad() { super.viewDidLoad() textInputScreen.delegate = self } func textFieldShouldReturn(_ textField: UITextField) -> Bool { // textField

My TextField is not editable

耗尽温柔 提交于 2019-12-13 16:15:30
问题 I know it is a very simple Question, but the TextField is not Editable. I have three UIViews, in each UIView contains three TextFields. The TextFields in the 2nd and 3rd UIView are working perfectly. But in the TextFields in the 1st UIView are really weird. Let the TextFields are First, Middle , Last Name . First TextField is working fine, Middle is working only sometimes (it means i need to touch several times) and at last, the Last Name TextField is COMPLETELY not working. What could be the