Contents

조회 수 2686 댓글 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] 설정에서 푸시 알림(APNS) on/off 상태 확인

    Date2015.04.28 CategoryDevelop Byhooni Views2049
    Read More
  2. [ios] GPS 이용 상태 확인

    Date2015.04.27 CategoryDevelop Byhooni Views1298
    Read More
  3. [js] jQuery, Javascript 모바일(스마트폰) 판단하는 방법

    Date2015.04.26 CategoryDevelop Byhooni Views2454
    Read More
  4. [ppt] iOS 플라랩#03(2015.04.27) 발표 자료

    Date2015.04.24 CategoryPPT Byhooni Views1066
    Read More
  5. [ppt] iOS 플라랩#02(2015.03.19) 발표 자료

    Date2015.04.24 CategoryPPT Byhooni Views904
    Read More
  6. WM미통기 - 10. 조건부확률

    Date2015.04.20 CategoryEtc Byhooni Views710
    Read More
  7. 수리통계학 : 표본공간과 사상-1

    Date2015.04.20 CategoryEtc Byhooni Views905
    Read More
  8. EBS [수학영역] 미적분과 통계 기본 - 정규분포의 의미와 특징은?

    Date2015.04.20 CategoryEtc Byhooni Views1006
    Read More
  9. [js] e.stopPropagation() VS e.preventDefault ()

    Date2015.04.14 CategoryDevelop Byhooni Views813
    Read More
  10. [js] 모바일 스크롤 방지(해제)

    Date2015.04.14 CategoryDevelop Byhooni Views1593
    Read More
  11. [js] 스크롤 이벤트 막기

    Date2015.04.14 CategoryDevelop Byhooni Views1012
    Read More
  12. [ios] 앱에서 설정화면 호출하기

    Date2015.04.07 CategoryDevelop Byhooni Views750
    Read More
Board Pagination Prev 1 ... 13 14 15 16 17 18 19 20 21 22 ... 98 Next
/ 98