Contents

Views 2675 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
285 Develop [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle) file hooni 2014.05.09 4451
284 Develop [ios] 앱 딜리게이트 얻어오기. (AppDelegate) hooni 2014.05.10 3341
283 Develop [ios] URL 파라미터 파싱~ hooni 2014.05.12 3670
282 Develop [ios] 언어, 지역, 국가 설정 가져오기 hooni 2014.05.12 269678
281 Develop [ios] 아이폰 GPS 사용하기 hooni 2014.05.24 3947
280 Develop [ios] iOS에서 디바이스 종류 알아오기 hooni 2014.05.24 3645
279 Develop 알고리즘 성능분석 file hooni 2014.06.24 2963
278 Develop 알고리즘 성능 분석 기준 hooni 2014.06.24 2783
277 Develop [ios] XCode에서 Provisioning Profile 여러개 중복될 때 hooni 2014.06.26 2814
» Develop [ios] TextField 특정 문자만 사용하도록 하기 hooni 2014.06.30 2675
275 Algorithm OCB5 Injection 앗싸뵹! ㅋㅋ file hooni 2014.07.01 796
274 Develop [ios] @property의 속성 (strong, weak, copy) 사용 경우 hooni 2014.08.08 1654
Board Pagination Prev 1 ... 70 71 72 73 74 75 76 77 78 79 ... 98 Next
/ 98