조회 수 2789 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
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] Using protobuf(Protocol Buffers) on iPhone (iOS)

    Date2014.03.20 CategoryDevelop Byhooni Views5019
    Read More
  2. [PHP] Mac OS에서 PHP 7 설치하기

    Date2018.05.11 CategoryDevelop Byhooni Views5049
    Read More
  3. [c] 윈도우 API Viewport와 Window

    Date2013.04.23 CategoryDevelop Byhooni Views5982
    Read More
  4. [js] 자바스크립트 escape()를 PHP로 받기

    Date2013.04.23 CategoryDevelop Byhooni Views6003
    Read More
  5. [doc] C++언어 문법 설명서

    Date2013.04.23 CategoryDevelop Byhooni Views6194
    Read More
  6. [js] 서서히 나타나는 화면.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views6229
    Read More
  7. [java] 에디터.. swing 사용

    Date2013.04.23 CategoryDevelop Byhooni Views6335
    Read More
  8. [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거..

    Date2013.04.23 CategoryDevelop Byhooni Views6345
    Read More
  9. [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기

    Date2013.04.23 CategoryDevelop Byhooni Views6363
    Read More
  10. [c] 다중연결 서버 만들기 #3 - poll() 사용

    Date2013.04.23 CategoryDevelop Byhooni Views6369
    Read More
  11. [java] 채팅창 처럼2.. swing..

    Date2013.04.23 CategoryDevelop Byhooni Views6450
    Read More
  12. [doc] C언어 문법 설명서

    Date2013.04.23 CategoryDevelop Byhooni Views6459
    Read More
  13. [c] 메세지 프로그램 (Server - Agent - Client)

    Date2013.04.23 CategoryDevelop Byhooni Views6479
    Read More
  14. [js] 윤동이가 만든 영어 학습(?) 프로그램

    Date2013.04.23 CategoryDevelop Byhooni Views6479
    Read More
  15. [c] 네트워크 보안 프로그래밍 과제 (Server,Agent,Client)

    Date2013.04.23 CategoryDevelop Byhooni Views6493
    Read More
  16. [php] 정규표현식 간단히 정리

    Date2013.04.23 CategoryDevelop Byhooni Views6507
    Read More
Board Pagination Prev 1 ... 12 13 14 15 16 ... 53 Next
/ 53