uitextfield

how to add 2 textfields togethers as int (swift3)

无人久伴 提交于 2019-12-02 13:08:17
I am trying to convert 2 textfields to ints and then add them together. I would also like to print the sum in the log. let jake = t3.text! + t4.text! Convert text into Int in Swift and an addition like we can do... //set before this condition Validation for Text field let sum = (Int(textFirst.text ?? "0")! + Int(textSecond.text ?? "0"))! print(sum) //Output here //MARK: - Text Field Delegate Method for Input validation func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let allowedCharacters = CharacterSet.decimalDigits

How to add followed text to uitextfield

浪子不回头ぞ 提交于 2019-12-02 12:08:53
问题 I have one text field with place holder called letschat . Now whenever I start typing in my textfield, I want to show my textfield as some @letschat . When my textfield is empty that time my placeholder have to show. That I did. But I want to set whenever I start typing in my textfield. Whatever I am typing with that I want this text also to visible like: Some @Lletschat How can I do this? 回答1: I created a UITextField subclass that uses the placeholder (if set) as a suffix. As far as I can

UITextField show cursor even when userInteractionEnabled is set to NO

北城以北 提交于 2019-12-02 12:01:53
问题 I have a UITextField and it must blink the cursor anyway, even its userInteractionEnabled property is set to NO. I don't want the UITextField to becomeFirstResponder and show the keyboard. Now you may be asking: 1. If you want to hide the keyboard, why to show the cursor? A: The problem is that I need to show the user the UITextField is being edited, with a different/custom keyboard. 2. So why don't you use the inputView property? A: Because the keyboard in inputView comes up from bottom, and

Adding a minus sign to the UITextField's .NumberPad keyboard

霸气de小男生 提交于 2019-12-02 11:45:38
问题 Fairly new to iOS development so forgive me for asking something that might be quite obvious. As you all know the UITextField's keyboard with keyboardType set to .NumberPad looks like the following... .NumberPad keyboard What I would like to do is replace the empty space in the lower left corner with a minus sign. Is this possible or does one need to write an entire custom keyboard to achieve this? Would really appreciate the help. 回答1: Add a toolbar to your textfield inputAccessoryView and

UICollectionView - When the keyboard appears the entire collection view is shifted with the keyboard

眉间皱痕 提交于 2019-12-02 11:10:40
This isn't my desired effect. This only happens when the collection view is set to horizontal flow layout. I've seen a few other posts regarding this very same issue but none of the provided answers have worked. Has anyone found a solution? I've provided two screenshots showing a UITextField before the keyboard is triggered and after. As you can see the UITextField along with the entire collection view (which can't be seen) is pushed up along with the keyboard. Usually the keyboard is overlayed having no effect on the views. Before After Update Code provided. The method I used to implement

Validation for input string is CivilID or not?

北城余情 提交于 2019-12-02 11:06:41
I have got a UITextfield with the following format . It is a Civil ID which we usually get to see in Gulf Countries. So I need to validate the same in my UITextfield in Swift. Civil ID format - NYYMMDDNNNNN where N a digit, YY last two digits of birth year, MM birth month, DD birth date.. Please tell me how to do validation for this. I am currently validating the Date of Birth using the objective c code: NSString *dateFromTextfield = @"07/24/2013"; // Convert string to date object NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"MM/dd/yyyy"];// here set

Bug? UILabel live updating by UITextFieldDelegate is off by one character

风流意气都作罢 提交于 2019-12-02 10:39:13
问题 Here is a sample app to demonstrate the issue that I ran into: import UIKit class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var aTextField: UITextField! @IBOutlet weak var aTextLbl: UILabel! override func viewDidLoad() { super.viewDidLoad() aTextField.delegate = self } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { aTextLbl.text = aTextField.text return true } } Here is a demo: Link to

Numbers separated by commas in UITextField not working

 ̄綄美尐妖づ 提交于 2019-12-02 10:05:28
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 = [numberFormat numberFromString:textField.text]; textField.text = [numberFormat stringFromNumber:amount]; return

Assigning Character Limit to a Specific UITextField

断了今生、忘了曾经 提交于 2019-12-02 09:50:58
The following code works but applies to all TextFields. How can I limit it to one specific TextField? Code: func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let currentCharacterCount = (textField.text?.characters.count) ?? 0 if (range.length + range.location > currentCharacterCount){ return false } let newLength = currentCharacterCount + string.characters.count - range.length return newLength <= 9 } Assuming that you have two textFields and your controller is a delegate of both. @IBOutlet var aMagesticTextField:

Weird error while using UITextFieldDelegate

我与影子孤独终老i 提交于 2019-12-02 09:41:22
I have this error while messing with UITextField delegate: Can't find keyplane that supports type 8 for keyboard Wildcat-Landscape-QWERTY-Pad; using 3673479387_Wildcat-Alphabetic-Keyboard_Capital-Letters Someone have any idea what is it? Thanks in advance. for iPad you can't use keyboard type: Decimal Pad ; you must change it to Number and Punctuation , etc 来源: https://stackoverflow.com/questions/16486312/weird-error-while-using-uitextfielddelegate