Programmatically Select all text in UITextField

Thats what did the trick for me: [self.titleField setSelectedTextRange:[self.titleField textRangeFromPosition:self.titleField.beginningOfDocument toPosition:self.titleField.endOfDocument]]; Pretty ugly but it works, so there will be no sharedMenuController shown! To fix the “only works every second time” problem use following: __weak typeof(self) weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ __strong __typeof(weakSelf) strongSelf = weakSelf; UITextRange *range = [strongSelf textRangeFromPosition:strongSelf.beginningOfDocument toPosition:strongSelf.endOfDocument]; [strongSelf setSelectedTextRange:range]; }); … Read more

Formatting a UITextField for credit card input like (xxxx xxxx xxxx xxxx)

If you’re using Swift, go read my port of this answer for Swift 4 and use that instead. If you’re in Objective-C… Firstly, to your UITextFieldDelegate, add these instance variables… NSString *previousTextFieldContent; UITextRange *previousSelection; … and these methods: // Version 1.3 // Source and explanation: http://stackoverflow.com/a/19161529/1709587 -(void)reformatAsCardNumber:(UITextField *)textField { // In order to make the … Read more

Indent the text in a UITextField

This is the quickest way I’ve found without doing any subclasses: UIView *spacerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; [textfield setLeftViewMode:UITextFieldViewModeAlways]; [textfield setLeftView:spacerView]; In Swift: let spacerView = UIView(frame:CGRect(x:0, y:0, width:10, height:10)) textField.leftViewMode = UITextFieldViewMode.Always textField.leftView = spacerView Swift 5: let spacerView = UIView(frame:CGRect(x:0, y:0, width:10, height:10)) textField.leftViewMode = .always textField.leftView = spacerView

Check that a input to UITextField is numeric only

You can do it in a few lines like this: BOOL valid; NSCharacterSet *alphaNums = [NSCharacterSet decimalDigitCharacterSet]; NSCharacterSet *inStringSet = [NSCharacterSet characterSetWithCharactersInString:myInputField.text]; valid = [alphaNums isSupersetOfSet:inStringSet]; if (!valid) // Not numeric — this is for validating input is numeric chars only. Look at the documentation for NSCharacterSet for the other options. You can use characterSetWithCharactersInString … Read more

How to add a ‘Done’ button to numpad keyboard in iOS

The much safer approach is to use a UIToolBar with Done Button as inputAccessoryView. Sample Code : UIToolbar *keyboardDoneButtonView = [[UIToolbar alloc] init]; [keyboardDoneButtonView sizeToFit]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@”Done” style:UIBarButtonItemStyleBordered target:self action:@selector(doneClicked:)]; [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]]; txtField.inputAccessoryView = keyboardDoneButtonView; Your -doneClicked method should look like this : – (IBAction)doneClicked:(id)sender { NSLog(@”Done Clicked.”); [self.view … Read more

How do you obscure text in a password field in an iPhone Application?

I don’t really understand your question, but I’m guessing you want a UITextField which displays dots for the characters, which every password field on the iPhone does. For this, you want to set the secureTextEntry property of that UITextField (UITextField has such a property because it conforms to the UITextInputTraits protocol) to YES: textfield.secureTextEntry = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)