Views 2684 Votes 0 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. [ios] 카테고리 확장 메소드를 찾지 못하는 경우

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

    Date2014.08.08 CategoryDevelop Byhooni Views1664
    Read More
  3. OCB5 Injection 앗싸뵹! ㅋㅋ

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

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

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

    Date2014.06.24 CategoryDevelop Byhooni Views2792
    Read More
  7. 알고리즘 성능분석

    Date2014.06.24 CategoryDevelop Byhooni Views2972
    Read More
  8. [ios] iOS에서 디바이스 종류 알아오기

    Date2014.05.24 CategoryDevelop Byhooni Views3655
    Read More
  9. [ios] 아이폰 GPS 사용하기

    Date2014.05.24 CategoryDevelop Byhooni Views3960
    Read More
  10. [ios] 언어, 지역, 국가 설정 가져오기

    Date2014.05.12 CategoryDevelop Byhooni Views269994
    Read More
  11. [ios] URL 파라미터 파싱~

    Date2014.05.12 CategoryDevelop Byhooni Views3680
    Read More
  12. [ios] 앱 딜리게이트 얻어오기. (AppDelegate)

    Date2014.05.10 CategoryDevelop Byhooni Views3348
    Read More
  13. [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle)

    Date2014.05.09 CategoryDevelop Byhooni Views4461
    Read More
  14. [ios] 애플 앱스토어 IDFA 리뷰 정책 변경 안내

    Date2014.05.07 CategoryDevelop Byhooni Views4187
    Read More
  15. [ios] NSString URL Encode/Decode (인코딩/디코딩)

    Date2014.05.02 CategoryDevelop Byhooni Views3422
    Read More
  16. [ios] 커스텀 폰트 사용하기 (Custom Fonts)

    Date2014.04.30 CategoryDevelop Byhooni Views3141
    Read More
Board Pagination Prev 1 ... 16 17 18 19 20 ... 74 Next
/ 74