Contents

조회 수 2671 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Xcode의 TextField 사용할때 특정 문자만 입력 받도록 하기 위해서는 다음과 같이 한다.

예) 숫자와 영문자만 입력 받기 
#define LEGAL_TEXT @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
     NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL_TEXT] invertedSet];
     NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
     return [string isEqualToString:filtered];
}


예2) 숫자와 소수점만 입력 받기 (소수점이 입력된 뒤에는 숫자만 입력 받는다)
 
키패드 타입을 변경 
entryField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

#define NUMBERS	@"0123456789"
#define NUMBERSPERIOD	@"0123456789."

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs;
    NSString *filtered;

    // Check for period
    if ([entryField.text rangeOfString:@"."].location == NSNotFound)
    {
        cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSPERIOD] invertedSet];
        filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
        return [string isEqualToString:filtered];
    }

    // Period is in use
    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];
    filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    return [string isEqualToString:filtered];
}

[출처] http://comxp.tistory.com/250


?

  1. '2014 모바일 개발 트렌드' 발표자료입니다.

    Date2014.10.02 CategoryDevelop Byhooni Views974
    Read More
  2. [ios] iOS 8 개발자가 우선 알아야 할 3가지

    Date2014.10.02 CategoryDevelop Byhooni Views896
    Read More
  3. [js] jQuery 셀 병합

    Date2014.09.23 CategoryDevelop Byhooni Views3486
    Read More
  4. IoT가 만드는 미래와 플랫폼 경쟁력

    Date2014.09.23 CategoryEtc Byhooni Views0
    Read More
  5. SVN(Subversion) 설치와 설정 (sasl 인증 적용 포함)

    Date2014.09.11 CategorySystem/OS Byhooni Views5654
    Read More
  6. [linux] yum 업데이트 시 커널 제외하기

    Date2014.09.11 CategorySystem/OS Byhooni Views1254
    Read More
  7. [ios] Xcode cannot run using the selected device

    Date2014.08.14 CategoryDevelop Byhooni Views1783
    Read More
  8. [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define

    Date2014.08.08 CategoryDevelop Byhooni Views1854
    Read More
  9. [ios] 카테고리 확장 메소드를 찾지 못하는 경우

    Date2014.08.08 CategoryDevelop Byhooni Views1989
    Read More
  10. [ios] @property의 속성 (strong, weak, copy) 사용 경우

    Date2014.08.08 CategoryDevelop Byhooni Views1651
    Read More
  11. OCB5 Injection 앗싸뵹! ㅋㅋ

    Date2014.07.01 CategoryAlgorithm Byhooni Views793
    Read More
  12. [ios] TextField 특정 문자만 사용하도록 하기

    Date2014.06.30 CategoryDevelop Byhooni Views2671
    Read More
Board Pagination Prev 1 ... 18 19 20 21 22 23 24 25 26 27 ... 98 Next
/ 98