uitextfield

Add a button on right view of UItextfield in such way that, text should not overlap the button

僤鯓⒐⒋嵵緔 提交于 2019-12-02 17:34:53
I can add a button to a textfield on the right hand side of the UITextField using the right view however, the text overlaps on the button. Below is the code for right view button UIView.commitAnimations() var btnColor = UIButton(type: .Custom) btnColor.addTarget(self, action: #selector(self.openEmoji), forControlEvents: .TouchUpInside) btnColor.frame = CGRect(x: CGFloat(textField.frame.size.width - 25), y: CGFloat(5), width: CGFloat(25), height: CGFloat(25)) btnColor.setBackgroundImage(UIImage(named: "send.png"), forState: .Normal) textField.addSubview(btnColor) Please let me know how to give

How to make a UIScrollView auto scroll when a UITextField becomes a first responder

无人久伴 提交于 2019-12-02 17:31:56
I've seen posts around here that suggest that UIScrollViews should automatically scroll if a subview UITextField becomes the first responder; however, I can't figure out how to get this to work. What I have is a UIViewController that has a UIScrollView and within the UIScrollView there are multiple textfields. I know how to do this manually if necessary; however, from what I've been reading, it seems possible to have it autoscroll. Help please. I hope this example will help you You can scroll to any point by this code. scrollView.contentOffset = CGPointMake(0,0); So if you have textfield, it

Numbers separated by commas in UITextField not working

﹥>﹥吖頭↗ 提交于 2019-12-02 17:26:51
问题 I'm trying to add a decimal after every 3 characters. (Counting backwards like this: 1,325,541 instead of 1325451.) Here is what I tried: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSNumberFormatter *numberFormat = [[NSNumberFormatter alloc] init]; [numberFormat setGroupingSeparator:@","]; [numberFormat setGroupingSize:3]; [numberFormat setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *amount =

Custom UITextField clear button

你说的曾经没有我的故事 提交于 2019-12-02 17:03:52
Is it possible to customize the image of the clear button in a UITextField ? I have a dark textfield background and the "x" is not visible enough. Danra You can set your own custom clear button to the text field's rightView property. Make sure set the rightViewMode property to UITextFieldViewModeWhileEditing or UITextFieldViewModeAlways , whatever makes sense for your case. If the button's position isn't right for your need, you can subclass UITextField and override the rightViewRectForBounds: method. The documentation says the default for the clearButtonMode property is

How to set letter spacing of UITextField

删除回忆录丶 提交于 2019-12-02 17:03:37
I have an app in which the user has to type a four digit pin code. All digits have to be at a set distance from each other. Is there a way to do this if the PinTextField is a subclass of UIView ? I know in a ViewController you could use UITextFieldTextDidChangeNotification and set the attributed text for each change. Notifications don't seem to work in a UIView though. Also I was wondering if there isn't a simpler way than making an attributed string for every update if you want to set the letter spacing of a UITextField text ? Correct spacing: Wrong spacing: iOSer No need to go for

Clear UITextField Placeholder text on tap

别说谁变了你拦得住时间么 提交于 2019-12-02 16:44:13
In Xcode4 I've created some placeholder text for a UITextField and I'd like it to clear when the user taps in the box. So, in the Attributes Inspector for the text field I've clicked "Clear when editing begins" however this does not immediately remove the text when I tap in the text box (it only disappears when you start typing). Is there any way of removing the placeholder text immediately on tapping in the text box? make your ViewController the delegate of the textField and implement those two methods: - (void)textFieldDidBeginEditing:(UITextField *)textField { textField.placeholder = nil; }

Format UITextField text without having cursor move to the end

人走茶凉 提交于 2019-12-02 16:38:57
I am trying to apply NSAttributedString styles to a UITextField after processing a new text entry, keystroke by keystroke. The problem is that any time I replace the text the cursor will jump the very end on each change. Here's my current approach … Receive and display text change immediately (same issue applies when I return false and do the text replacement manually) func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool { let range:NSRange = NSRange(location: range.location, length: range.length) let newString =

How to scroll view up when keyboard appears?

此生再无相见时 提交于 2019-12-02 16:35:59
I know that this question has been asked over and over again, but nothing seems to be working for me. Most of the solutions around are pretty out of date, and the rest are incredibly huge blocks of code that are ten times larger then the actual projects coding. I have a few UITextFields lined up vertically, but when the keyboard launches to edit one, it covers up the text field. I was wondering if there is a simple beginner way to scroll the view up, and then back down when the editing starts and ends? Thank you. I have made solutions that work with scroll and non-scroll views using keyboard

Checking if text fields are empty cause error in Swift 2

南笙酒味 提交于 2019-12-02 15:54:08
问题 I am trying to check if a textbox has no value. When I do this: if(userEmail?.isEmpty || userPassword?.isEmpty || userPasswordRepeat?.isEmpty) I get the following error I tried adding "?" before the ".isEmpty" but the error won't go away Any ideas? 回答1: Try this.... if txtEmail.text?.isEmpty == true || txtPassword.text?.isEmpty == true || txtRePassword.text?.isEmpty == true{ print("true") } 回答2: If interested also in positive case, the following is an alternative solution for Swift 2 : let

UITextField auto-capitalization type - iPhone App

拟墨画扇 提交于 2019-12-02 15:41:09
Is there a way to set the autocapitalizationType for a UITextField so that the first letter of each word is capitalized by default? This Is An Example Of What I Want AlexVogel Use textField.autocapitalizationType = UITextAutocapitalizationTypeWords; For more information please read: UITextInputTraits Protocol Reference nhgrif What we want to do is set the text field's autocapitalizationType . Objective-C: self.textfield.autocapitalizationType = UITextAutocapitalizationTypeWords Swift: self.textfield.autocapitalizationType = .words There are a few options here: allCharacters is the same as