Develop
2014.06.30 11:13
[ios] TextField 특정 문자만 사용하도록 하기
조회 수 3896 댓글 0
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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
913 | Develop |
[c] 네트워크 정보 알아보기
![]() |
hooni | 2013.04.23 | 16971 |
912 | Etc |
여기저기서 모은 VoIP(인터넷전화) 자료들~
![]() |
hooni | 2013.04.23 | 16961 |
911 | Develop | OGNL(Object Graph Navigation Language) | hooni | 2013.04.23 | 16960 |
910 | System/OS | [linux] 종료와 종료코드 확인(환경변수에서) | hooni | 2003.04.23 | 16909 |
909 | Algorithm | [algorithm] Greedy (탐욕 기법) | hooni | 2003.04.23 | 16828 |
908 | PPT |
[ppt] 웜 과제 진행사항(프레임워크 검증환경 구축) 보고
![]() |
hooni | 2013.04.23 | 16801 |
907 | System/OS |
[owasp] 10대 웹어플리케이션 보안 취약
![]() |
hooni | 2013.04.23 | 16762 |
906 | System/OS |
라우팅 경로 결정 영향 요소 ㅋㅋ
![]() |
hooni | 2013.04.23 | 16738 |
905 | Develop | [erp] SAP 모듈 요약 | hooni | 2013.04.23 | 16603 |
904 | Develop |
[c] 윈도우 API sin 함수 출력..
![]() |
hooni | 2013.04.23 | 16533 |
903 | Develop | [android] 해상도 관련 팁 (dip -> pixel 변환) | hooni | 2013.04.23 | 16517 |
902 | Etc | 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ | hooni | 2013.06.17 | 16495 |