툴바에 세그먼트 컨트롤을 삽입하는데 IB에서는 그냥 드래그 해서 잘만 되더만
코드로는 어떻게 하는지 잘 모르겠더라...
아래와 같이 하면 되더라~^^
self는 UIToolbar 상속 받은 클래스다.
#define TOOLBARBUTTON(TITLE, STYLE, SELECTOR) [[[UIBarButtonItem alloc] initWithTitle:TITLE style:STYLE target:self action:SELECTOR] autorelease] NSMutableArray *tbitems = [NSMutableArray array]; [tbitems addObject:TOOLBARBUTTON(@"아이템1", UIBarButtonItemStyleBordered, @selector(action))]; [tbitems addObject:TOOLBARBUTTON(@"아이템2", UIBarButtonItemStyleBordered, @selector(action))]; UIBarButtonItem *bbi = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease]; bbi.width = 350.0f; [tbitems addObject:TOOLBARBUTTON(@"아이템3", UIBarButtonItemStyleBordered, @selector(action))]; self.items = tbitems; NSArray *buttonNames = [NSArray arrayWithObjects:@"세그1", @"세그2", nil]; UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:buttonNames]; segmentedControl.frame = CGRectMake(250.0f, 8.0f, 120.0f, 30.0f); segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.selectedSegmentIndex = 0; [segmentedControl setWidth:70 forSegmentAtIndex:0]; [segmentedControl setWidth:90 forSegmentAtIndex:1]; [segmentedControl setTintColor:[UIColor darkGrayColor]]; [self addSubview:segmentedControl]; [segmentedControl release];
'프로그램 경험 > iOS' 카테고리의 다른 글
[iPhone] Navigation Controller에 다중 뷰를 넣을때 문제 (0) | 2010.09.16 |
---|---|
[iPhone] Segmented Control의 Momentary 속성은 무엇인가? (0) | 2010.09.16 |
[iPhone] 아이패드 확인하기 (0) | 2010.09.15 |
[iPhone] iPhone으로 세션을 시작할 수 없기 때문에... (0) | 2010.09.14 |
[iPhone] 아이폰 4.1 버전 업그레이드 이후 기기 연동안됨 (0) | 2010.09.14 |