Develop
2013.08.08 13:07
[ios] 소소한 팁 (Rect,Point,Path,URL 등)
조회 수 29534 댓글 0
1. 빌드시 시뮬레이터 판별
2. 하위 View 검색
초기화 하는 곳에서 [self setSubViewsClearColor:self]; 와 같이 호출하여 사용합니다.
3. 사용자 데이터 저장
4. Rect와 Point
좌표로 많이 사용되는 Rectd와 Point에서 자주 사용되는 함수와 상수입니다.
5. Path
6. URL
#if !TARGET_IPHONE_SIMULATOR
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
TARGET_IPHONE_SIMULATOR로 실제 아이폰에서만 실행되는 코드를 따로 관리할 수 있습니다. pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
2. 하위 View 검색
NSArray *subViewList = [searchBar subviews];
for (UIView *view in subViewList) {
if ([view isKindOfClass:[UITextField class]]) {
[(UITextField *)view setReturnKeyType:UIReturnKeyDone];
}
}
UIView의 subviews와 isKindOfClass를 사용하여 하위의 특정 뷰를 찾아내어 설정을 변경할 수 있습니다. UISearchBar에서 UITextField를 찾아내어 키보드의 Search 버튼의 텍스트를 Done으로 변경하는 예입니다.for (UIView *view in subViewList) {
if ([view isKindOfClass:[UITextField class]]) {
[(UITextField *)view setReturnKeyType:UIReturnKeyDone];
}
}
- (void) setSubViewsClearColor: (UIView*)theView {
NSArray *subViewList = theView.subviews;
for (UIView *view in subViewList) {
[view setBackgroundColor:[UIColor clearColor]];
[self setSubViewsClearColor:view];
}
}
하위 View를 모두 찾아 배경을 투명한 속성으로 변경하는 예입니다. NSArray *subViewList = theView.subviews;
for (UIView *view in subViewList) {
[view setBackgroundColor:[UIColor clearColor]];
[self setSubViewsClearColor:view];
}
}
초기화 하는 곳에서 [self setSubViewsClearColor:self]; 와 같이 호출하여 사용합니다.
3. 사용자 데이터 저장
userLevel = [[NSUserDefaults standardUserDefaults] integerForKey:@"user_level"];
[[NSUserDefaults standardUserDefaults] setInteger:g_userLevel forKey:@"user_level"];
옵션등의 간단한 설정은 데이터베이스나 파일을 이용하는대신 NSUserDeraults를 사용하면 간단하게 저장하고 불러올 수 있습니다.[[NSUserDefaults standardUserDefaults] setInteger:g_userLevel forKey:@"user_level"];
4. Rect와 Point
좌표로 많이 사용되는 Rectd와 Point에서 자주 사용되는 함수와 상수입니다.
CGRect CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height);
x, y, width, height로 설정된 CGRect를 반환합니다.CGRectZero
0, 0 좌표와 0, 0 크기를 가진 CGRect 상수입니다.CGPointMake(CGFloat x, CGFloat y);
x, y로 설정된 CGPoint를 반환합니다.CGPointZero
0, 0 좌표를 가진 CGPoint 상수입니다.bool CGRectContainsPoint(CGRect rect, CGPoint point);
rect 사각형에 point가 속해있는지 여부를 반환합니다.bool CGRectContainsRect(CGRect rect1, CGRect rect2);
rect1 사각형에 rect2 사각형이 속해있는지 여부를 반환합니다.bool CGRectIntersectsRect (CGRect rect1, CGRect rect2);
rect1과 rect2가 교차하는지 여부를 반환합니다.5. Path
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
어플리케이션 번들 디렉토리를 반환합니다.NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
번들에 포함된 파일들은 읽기만 가능하고 쓰기가 불가능합니다. 디비와 같이 변경이 필요한 경우에는 위와같이 어플리케이션의 도큐먼트 폴더를 구해와 도큐먼트 폴더로 복사 생성해 놓고 작업합니다.NSString *documentsDirectory = [paths objectAtIndex:0];
6. URL
NSURL *url = [NSURL URLWithString:@"http://www.cocoadev.co.kr"];
[[UIApplication sharedApplication] openURL:url];
지정된 웹주소를 사파리에서 오픈합니다.[[UIApplication sharedApplication] openURL:url];
NSURL *url = [NSURL URLWithString:@"mailto:abc@def.com"];
[[UIApplication sharedApplication] openURL:url];
받는사람이 설정되어 메일 프로그램의 새로운 메시지가 실행됩니다.[[UIApplication sharedApplication] openURL:url];
NSURL *url = [NSURL URLWithString:@"tel:02-111-2222"];
[[UIApplication sharedApplication] openURL:url];
지정된 번호로 전화를 겁니다.[[UIApplication sharedApplication] openURL:url];
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
577 | Develop | [c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ | hooni | 2013.04.23 | 6915 |
576 | Develop | [c] 프로세스간의 통신(파이프) | hooni | 2003.04.23 | 6915 |
575 | Develop | [c] 맵서치인 듯(옛날 컴에서 찾은 자료) | hooni | 2013.04.23 | 6916 |
574 | Develop | [c] 단기과정[01/10] 과제.. swap(any data, ..) | hooni | 2003.04.23 | 6933 |
573 | Develop | [c] 프로세스 정보 출력하기.. | hooni | 2003.04.23 | 6938 |
572 | Develop | [c] 소켓의 세가지 동작모드 | hooni | 2003.04.23 | 6943 |
571 | Develop | [c] 숫자 맞추는 게임.. | hooni | 2013.04.23 | 6953 |
570 | Develop | [js] php의 number_format() 함수와 같은.. ㅋㅋ | hooni | 2013.04.23 | 6953 |
569 | Develop | [c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷) | hooni | 2013.04.23 | 6954 |
568 | Develop | [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ | hooni | 2013.04.23 | 6955 |
567 | Develop | [c] 단기과정[01/06] sizeof, 실수표현, 메모리, 연산자 | hooni | 2003.04.23 | 6961 |
566 | Develop | 라이브러리에 대한 설명 (static & dynamic library) | hooni | 2013.04.23 | 6969 |