Contents

Views 2797 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
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. GPL, AGPL, MPL,.. 한눈에 보는 오픈소스SW 라이선스

    Date2014.10.14 CategoryDevelop Byhooni Views1274
    Read More
  2. [js] 좋은 강연자료 & UI 자료

    Date2014.10.06 CategoryDevelop Byhooni Views997
    Read More
  3. '2014 모바일 개발 트렌드' 발표자료입니다.

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

    Date2014.10.02 CategoryDevelop Byhooni Views993
    Read More
  5. [js] jQuery 셀 병합

    Date2014.09.23 CategoryDevelop Byhooni Views3569
    Read More
  6. [ios] Xcode cannot run using the selected device

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

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

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

    Date2014.08.08 CategoryDevelop Byhooni Views1782
    Read More
  10. [ios] TextField 특정 문자만 사용하도록 하기

    Date2014.06.30 CategoryDevelop Byhooni Views2797
    Read More
  11. [ios] XCode에서 Provisioning Profile 여러개 중복될 때

    Date2014.06.26 CategoryDevelop Byhooni Views2953
    Read More
  12. 알고리즘 성능 분석 기준

    Date2014.06.24 CategoryDevelop Byhooni Views2920
    Read More
Board Pagination Prev 1 ... 10 11 12 13 14 15 16 17 18 19 ... 71 Next
/ 71