UITextView 키보드 위에 완료 버튼 만들기
개발/iOS1 2017. 7. 25. 15:23키보드 위에 완료 버튼 붙이기...
|
UITextView *m_pEditText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; m_pEditText.editable = YES; [m_pEditText setUserInteractionEnabled:YES]; [m_pEditText setBackgroundColor:[UIColor whiteColor]]; [m_pEditText setTextColor:[UIColor blackColor]]; [m_pEditText setKeyboardType:UIKeyboardTypeDefault];
// UITextView 키보드에 올릴 Bar 생성. UIToolbar* keyboardToolbar = [[UIToolbar alloc] init]; [keyboardToolbar sizeToFit]; UIBarButtonItem *flexBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; // 위아래 화살표 버튼
UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)]; // 완료 버튼 keyboardToolbar.items = @[flexBarButton, doneBarButton];
m_pEditText.inputAccessoryView = keyboardToolbar; |
위 코드를 사용 할 경우 아래 그림과 같이 나오게 된다.





