2010년 8월 31일 화요일

[XCode] 컨트롤에 포커스 주는 방법 (focus(), setfocus)

Application의 화면상에 있는 컨트롤에 포커스를 주거나 빼는 방법입니다.
대부분의 언어에서는 focus 라는 단어를 많이 사용하고 있는데,
iPhone 에서는 좀 많이 다르내요.
(좀 과하다는 생각이 들만큼 Apple의 가독성 위주 표기법에 두 손 들었습니다. )

1. 컨트롤에 포커스 주는 방법
[controller becomeFirstResponder];
  • controller는 포커스를 주려고 하는 컨트롤의 이름입니다.
  • “controller가 첫번째 응답자가 된다” 라는 의미입니다. (이건 뭐 소설도 아니고…)

2. 컨트롤에서 포커스 빼는 방법
[controller resignFirstResponder];
  • controller는 포커스를 빼려고 하는 컨트롤의 이름입니다.
  • “controller가 첫번째 응답자에서 물러나다” 라는 의미입니다.

최초응답자 : 화면상에서 가장먼저 응답하는 컨트롤,  Visual Studio 에서보면 TabIndex = 0 인 컨트롤,   결국 제일먼저 응답하니까 포커스를 받는다는 의미입니다.  

[iPhone Design] iPhone 화면 사이즈

iPhone Application 디자인 할때 참고 할 만한 자료입니다.




[XCode] alpha값 사용않하고 배경색 지우는 방법

Interface Builder를(alpha=0) 이용하지 않고, 소스상에서 배경색을 지우는 방법입니다

[UIColor clearColor];


아래의 소스를 이용해서 직접 확인해 보세요

=======================================================================
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptons {

    UILabel *notClearedbackground = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 280.0f, 50.0f)];
    [notClearedbackground setText:@"I have a background color"];
    [window addSubview:notClearedbackground];
    [notClearedbackground release];

    UILabel *clearedbackground = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 200.0f, 280.0f, 50.0f)];
    [clearedbackground setText:@"I'm transparent background"];
    [clearedbackground setBackgroundColor:[UIColor clearColor]];
    [window addSubview:clearedbackground];
    [clearedbackground release];

    [window setBackgroundColor:[UIColor grayColor]];
    [window makeKeyAndVisible];
}
=======================================================================

2010년 8월 23일 월요일

[Objective-C] NSString - Step 2





//공백과 탭 제거
NSString *stringBefore = @"                 I Wanna be a iPHone developer !! ";
NSString *stringAfter1 = [stringBefore stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSLog(@"whitespaceCharacterSet : %@", stringAfter1);


/* 결과
 whitespaceCharacterSet : I Wanna be a iPHone developer !!
 */

//공백과 탭 및 개행 제거
NSString *stringAfter2 = [stringBefore stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"whitespaceAndNewlineCharacterSet : %@", stringAfter2);


/* 결과
 whitespaceAndNewlineCharacterSet : I Wanna be a iPHone developer !!
 */

// 토큰(구분자)를 이용해서 NSString을 NSArray로 분리
NSString *string1 = @"I Wanna be a iPHone developer !!";
NSArray *array1 = [string1 componentsSeparatedByString:@" "];
NSLog(@"componentsSeparatedByString : %@", array1);


/* 결과
 componentsSeparatedByString : (
 I,
 Wanna,
 be,
 a,
 iPHone,
 developer,
 "!!"
 )
 */

//2. 여러 개의 토근을 사용할 경우
NSString *string2 = @"I-Wanna-be-a/iPHone-developer/!!";
NSArray *array2 = [string2 componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"-/"]];
NSLog(@"componentsSeparatedByCharactersInSet : %@", array2);


/* 결과
 componentsSeparatedByCharactersInSet : (
 I,
 Wanna,
 be,
 a,
 iPHone,
 developer,
 "!!"
 )
 */



//3. 스트링에 공백이 없고, 각 문자로 분리할 경우
NSString *string = @"abcdefghijklmn";
NSMutableArray *mArray = [[NSMutableArray alloc] initWithCapacity:[string length]];
for (int i = 0; i < [string length]; i++) {
NSString *ichar  = [NSString stringWithFormat:@"%c", [string characterAtIndex:i]];
[mArray addObject:ichar];
}
NSLog(@"%@", mArray);

/* 결과
  (
 a,
 b,
 c,
 d,
 e,
 f,
 g,
 h,
 i,
 j,
 k,
 l,
 m,
 n
 )
 */

//문자로 되어 있는 배열을 토큰(구분자)를 이용해서 다시 합치는 방법
NSArray *array3 = [NSArray arrayWithObjects:@"I", @"Wanna", @"be", @"a", @"iPHone", @"developer", @"!!", nil];
NSString *string3 = [array3 componentsJoinedByString:@" "];
NSLog(@"componentsJoinedByString : %@", string3);
NSString *string3_1 = [array3 componentsJoinedByString:@"-"];
NSLog(@"componentsJoinedByString : %@", string3_1);


/* 결과
 componentsJoinedByString : I Wanna be a iPHone developer !!
 componentsJoinedByString : I-Wanna-be-a-iPHone-developer-!!
 */

// 두 개의 문자열 합치는 방법
//case 1
NSString *string4_1 = @"I Wanna be";
NSString *string4_2 = @" a iPHone developer !!";
NSString *string4_3 = [string4_1 stringByAppendingString:string4_2];
NSLog(@"stringByAppendingString : %@", string4_3);

//case 2
NSString *string5_1 = @"I Wanna be";
NSString *string5_2 = @" a iPHone developer !!";
string5_1 = [string5_1 stringByAppendingString:string5_2];
NSLog(@"stringByAppendingString : %@", string5_1);

//case 3 : NSMutableString 인 경우...
NSMutableString *string6_1 = @"I Wanna be";
NSString *string6_2 = @" a iPHone developer !!";
[string6_1 appendString:string6_2];



// 입력받은 문자열이 원본 문자열에 포함되어 있는지 검색하는 방법
NSString *string7 = @"I wanna be a iPhone developer!";
NSString *text = @"be";
NSLog(@"원문 : %@", string7);
NSLog(@"찾을문자 : %@", text);


NSRange range = [string7 rangeOfString:text];
if(range.location == NSNotFound)
NSLog(@"not found");
else
{
NSLog(@"해당 문자열을 찾았습니다. ");
NSLog(@"after : %@", [string7 substringFromIndex:range.location]);
NSLog(@"before : %@", [string7 substringToIndex:range.location]);
NSLog(@"range : %@", [string7 substringWithRange:range]);
}


/*
 원문 : I wanna be a iPhone developer!
 찾을문자 : be
 해당 문자열을 찾았습니다. 
 after : be a iPhone developer!
 before : I wanna 
 range : be
 */

[Objective-C] NSString - Step 1

Objective-C에서 string 관련 처리 방법에 대해서 ....

// 빈 문자열 생성하기
NSString *mString1 = [NSString new];


//일반적인 문자열 대입 - 문자열 상수
mString1 = @"Hello World";


/*--------------------------------------------------
[참고]
%@ : 객체
%f : 실수
%d : 정수
%4d : 4자리 정수
%04d : 0으로 채운 4자리 정수
-------------------------------------------------- */


//포멧 문자열(stringWithFormat) - 변수 대입방식
NSString * mString2 = [NSString stringWithFormat:@"mString = %@", mString1];
NSLog(@"mString = %@", mString1);

//포멧 문자열(stringWithFormat) - 숫자 대입방식
NSString * mString3 = [NSString stringWithFormat:@"Integer Value is : %d", 12345];
NSLog(@"Integer Value is : %d", 12345);
//=> 출력 : "Integer Value is : 12345"
NSString * mString3_1 = [NSString stringWithFormat:@"Integer Value is : %4d", 12];
NSLog(@"Integer Value is : %4d", 12);
//=> 출력 : "Integer Value is : 12"
NSString * mString3_2 = [NSString stringWithFormat:@"Integer Value is : %04d", 12];
NSLog(@"Integer Value is : %04d", 12);
//=> 출력 : "Integer Value is : 0012"

//포멧 문자열(stringWithFormat) - 문자열 대입방식
NSString * mString4 = [NSString stringWithFormat:@"stringWithFormat : %s","Hello World"];
NSLog(@"stringWithFormat : %s","Hello World");


//Object-C형식 문자열
NSString * mString5 = [NSString stringWithString:@"Hello World"]; 


//C형식 문자열
NSString * mString6 = [NSString stringWithCString:@"This is"];


//문자열 Append (추가)
NSString * mString7 = [mString6 stringByAppendingString:@"my iPhone"];
// mString6 = "This is my iPhone"


//문자열 길이 구하기
int len = [mString8 length];

//String형을 int형으로 형변환하기
int intValue = [@"1234" intValue];

//String형을 float형으로 형변환하기
float flatValue = [@"1234.56" floatValue];

//메모리 할당한 문자열 변수 제거
[mString1 release];

더 자세한 내용은 XCode 도움말에서 NSString으로 검색해보세요

[기타] iPhone Jailbreak 에 관하여...

이 블로그에서는 iPhone(iPod, iPad) jailbreak (일명 탈옥)에 대해서는 관련자료를 올리지 않을예정입니다.


워낙 어둠의 경로에 많은 자료가 올라와 있고, 버전별 Upgrade가 자주 일어나서 그 때마다 정리한다는게 쉽지 않을거 같습니다.


이제는 Know Where 시대인 만큼 직접 찾아보는것도 능력개발(?)에 도움이 될겁니다.

[환경설정] iPhone 개발자 등록을 해보자

게이츠 형과는 사뭇 다른 잡스 형님의 마인드 덕택에 Apple의 개발자가 된다는게 생각보다는 손이 많이 가내요. ( 이누므 영어.... )


물론 늘 하던대로 어둠의 방법을 통해 단순 개발 정도는 가능하지만, 진정한 Apple의 iPhone(Mac, Safari) 개발자가 되기(App 등록, 판매) 위해서는 Apple 이라는 회사에 살짝 코가 껴야 되는게 현실.....


단계별 등록 및 작업절차를 정리한 자료가 있어서 링크 걸어봅니다.
그새 쫌 바뀐 부분이 있는거 같기는 한데, 크게 지장은 없는듯.
(역시 귀차니즘에서 나오는 최신버전으로의 정리에 대한 의지박약 ㅡㅡㅋ)




1. iPhone 개발자 등록 및 iPhone 개발자 라이센스 획득절차
=> http://tory45.egloos.com/5225109


2. iPhone Device 테스트 순서
=> http://tory45.egloos.com/5230002