Contents

Views 3886 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. [linux] split 명령어

    Date2014.03.11 CategorySystem/OS Byhooni Views5200
    Read More
  2. [ios][swift] 초간단 TableView 샘플

    Date2016.06.27 CategoryDevelop Byhooni Views5215
    Read More
  3. [ios] iOS 의 인앱구매 소개

    Date2014.04.29 CategoryDevelop Byhooni Views5250
    Read More
  4. [ios] URL Scheme 이용하여 앱 설치 확인

    Date2014.03.10 CategoryDevelop Byhooni Views5281
    Read More
  5. [linux] CentOS Apache Httpd에 https 적용

    Date2014.03.05 CategorySystem/OS Byhooni Views5327
    Read More
  6. [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle)

    Date2014.05.09 CategoryDevelop Byhooni Views5334
    Read More
  7. What is difference between Get, Post, Put and Delete?

    Date2018.02.28 CategoryDevelop Byhooni Views5335
    Read More
  8. [ios] iOS 7 이상 UIBarButtonItem 여백

    Date2014.03.27 CategoryDevelop Byhooni Views5379
    Read More
  9. [mysql] 중복데이터 삭제하는 초간단 쿼리

    Date2017.11.22 CategoryDatabase Byhooni Views5408
    Read More
  10. [android] 초간단 얼럿 (AlertDialog)

    Date2016.10.21 CategoryDevelop Byhooni Views5444
    Read More
  11. [ios] AES256 알고리즘을 이용해 데이터 암호화/복호화 방법

    Date2015.07.21 CategoryDevelop Byhooni Views5453
    Read More
  12. [linux] resolv.con 초기화 되는 문제

    Date2014.04.05 CategorySystem/OS Byhooni Views5454
    Read More
Board Pagination Prev 1 ... 17 18 19 20 21 22 23 24 25 26 ... 99 Next
/ 99