UITextField

2014. 10. 28. 17:52개발자료/iOS


반응형

## 글자수 입력 제한

Ex) 4자까지만 입력가능]

#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *newString = [textField.text stringByReplacingCharactersInRange:range
                                                                  withString:string];
    int length = [newString length] ;
    if (length >= 4) {
        textField.text = [newString substringToIndex:4];
        return NO;
    }
    return YES;
}

 

## 포커스 이동 

[textField becomeFirstResponder];

 

반응형

'개발자료 > iOS' 카테고리의 다른 글

UIViewController  (0) 2014.11.07
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=armv7s, VALID_ARCHS=armv7)  (0) 2014.10.28
UITableView  (0) 2014.10.28
핫스팟 상태체크(꼼수)  (0) 2014.10.28
UIDatePicker  (0) 2014.10.28