Contents

Views 3885 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


?

List of Articles
No. Category Subject Author Date Views
289 Develop [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle) file hooni 2014.05.09 5333
288 Develop [ios] 앱 딜리게이트 얻어오기. (AppDelegate) hooni 2014.05.10 4764
287 Develop [ios] URL 파라미터 파싱~ hooni 2014.05.12 4560
286 Develop [ios] 언어, 지역, 국가 설정 가져오기 hooni 2014.05.12 290678
285 Develop [ios] 아이폰 GPS 사용하기 hooni 2014.05.24 5024
284 Develop [ios] iOS에서 디바이스 종류 알아오기 hooni 2014.05.24 4602
283 Develop 알고리즘 성능분석 file hooni 2014.06.24 4257
282 Develop 알고리즘 성능 분석 기준 hooni 2014.06.24 3979
281 Develop [ios] XCode에서 Provisioning Profile 여러개 중복될 때 hooni 2014.06.26 3676
» Develop [ios] TextField 특정 문자만 사용하도록 하기 hooni 2014.06.30 3885
279 Algorithm OCB5 Injection 앗싸뵹! ㅋㅋ file hooni 2014.07.01 2513
278 Develop [ios] @property의 속성 (strong, weak, copy) 사용 경우 hooni 2014.08.08 2802
Board Pagination Prev 1 ... 70 71 72 73 74 75 76 77 78 79 ... 99 Next
/ 99