0

Thes is my code and i want to add underline part but i don't know how.

   #define ACCEPTABLE_CHARECTERS @"0123456789"


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string  {

if (textField==ucontact)
{        NSUInteger newLength = [textField.text length] + [string length] - range.length;

    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:ACCEPTABLE_CHARECTERS] invertedSet];

    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

    return (([string isEqualToString:filtered])&&(newLength <= 10));

}
return YES;
}
Shikha Sharma
  • 139
  • 1
  • 14
  • you are add underline in design or coding? – Bhadresh Kathiriya Sep 19 '16 at 05:58
  • Of course that's possible, just create an NSAttributedString with the properties you want (there are plenty of questions on SO for that) and set the text fields `attributedText` property. – HAS Sep 19 '16 at 06:12

2 Answers2

1

You can achieve it through the work around. You can add one line with the help of UIView below the textField and name it as the validatorView and change the color of the line according to your wish after validation.

Hope this helps best luck.

0

You can have a look at this question. It illustrates how you can make use of only the bottom border. Alternatively you can also add a line as a UIView subview.

I am curious why you do not use the Numpad keyboard.

textField.keyboardType = .NumberPad (Swift)

Community
  • 1
  • 1
Carien van Zyl
  • 2,853
  • 22
  • 30