이전 포스트인 키보드에 툴바 추가하기라는 포스트에서 다음 그림과 같은 키보드 상단에 버튼 등의 커스텀 기능을 추가하는 방법을 소개했었다. 그런데 iOS 3.2부터는 UITextView나 UITextField 클래스의 inputAccessoryView 프라퍼티를 통해 직접 객체에 원하는 컨트롤(버튼, 라벨, 슬라이더 등)을 추가할 수 있다. 또한 아예 키보드 자체를 다른 모양으로 교체할 수 있다. inputView 프라퍼티를 사용하면 된다. 물론 사용 방법은 inputAccessoryView를 사용하는 것과 동일하다. 이 번에는 간단히 inputAccessoryView를 사용한 예를 들어 본다.
viewDidLoad 메서드에 액세서리뷰를 생성한 후, 버튼을 만들어 추가하고 텍스트 필드의 inputViewAccessiory 프라퍼티에 할당하기만 하면 된다. 이 전에 사용한 방법보다 훨씬 간단하다.
- (void)viewDidLoad {
[super viewDidLoad];
// 액세서리뷰 생성.
UIView *inputAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 50.0)];
inputAccessoryView.backgroundColor = [UIColor darkGrayColor];
// 확인 버튼.
UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
confirmButton.frame = CGRectMake(210.0, 6.5, 100.0, 37.0);
[confirmButton setTitle: @"확인" forState:UIControlStateNormal];
[confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[confirmButton addTarget:self action:@selector(confirm:)forControlEvents:UIControlEventTouchUpInside];
[inputAccessoryView addSubview:confirmButton];
self.textField.inputAccessoryView = inputAccessoryView;
}
'프로그램 > iPhone' 카테고리의 다른 글
tableView에서 페이지 (0) | 2011.01.12 |
---|---|
iPhone UIButton 을 UISwitch(체크박스)처럼 이용하기 (0) | 2011.01.11 |
아이폰용 오픈소스/예제/참고자료 모음 (0) | 2011.01.04 |
how to debug EXC_BAD_ACCESS on iPhone (0) | 2011.01.03 |
아이콘과 로고-인트로-첫 화면 만들기 (0) | 2010.12.15 |