Contents

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


?

  1. [php][laravel] 라라벨 개발환경 세팅하기 (Mac, Window)

    Date2017.12.15 CategoryDevelop Byhooni Views2757
    Read More
  2. [js] show/hide 이벤트 감시 (Observing show/hide event)

    Date2021.02.03 CategoryDevelop Byhooni Views2764
    Read More
  3. [ios] TextField 특정 문자만 사용하도록 하기

    Date2014.06.30 CategoryDevelop Byhooni Views2771
    Read More
  4. [js] Javascript로 만든 포트리스 (2010)

    Date2017.03.03 CategoryDevelop Byhooni Views2803
    Read More
  5. [c#] 툴바 현재 욜심히 만들고 있는거.. 백업용.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views2852
    Read More
  6. Apache CORS 설정

    Date2020.09.04 CategorySystem/OS Byhooni Views2872
    Read More
  7. 알고리즘 성능 분석 기준

    Date2014.06.24 CategoryDevelop Byhooni Views2905
    Read More
  8. [ios] XCode에서 Provisioning Profile 여러개 중복될 때

    Date2014.06.26 CategoryDevelop Byhooni Views2937
    Read More
  9. How to Setup an Email Server on CentOS 7

    Date2018.04.05 CategorySystem/OS Byhooni Views3026
    Read More
  10. [ios] Objective-C 프로퍼티의 ATOMIC / NONATOMIC 속성

    Date2014.03.17 CategoryDevelop Byhooni Views3038
    Read More
  11. [js] Array.splice() 설명

    Date2014.04.24 CategoryDevelop Byhooni Views3059
    Read More
  12. [ios] iOS 사운드 관련 프레임워크

    Date2014.04.18 CategoryDevelop Byhooni Views3062
    Read More
Board Pagination Prev 1 ... 17 18 19 20 21 22 23 24 25 26 ... 98 Next
/ 98