inputAccessoryView的使用

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
self.myToolbar = toolbar;
[toolbar release];

UIBarButtonItem *lastButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"上一项" style:UIBarStyleBlackOpaque target:self action:@selector(getLastTextField)];
UIBarButtonItem *nextButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一项" style:UIBarStyleBlackOpaque target:self action:@selector(getNextTextField)];
UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *hiddenButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"隐藏键盘" style:UIBarStyleBlackOpaque target:self action:@selector(keyboardDown:)];

NSArray *array = [NSArray arrayWithObjects:lastButtonItem, nextButtonItem, spaceButtonItem, hiddenButtonItem, nil];
[self.myToolbar setItems:array];
[lastButtonItem release];
[nextButtonItem release];
[spaceButtonItem release];

myTextField.inputAccessoryView = self.myToolbar;
myTextField.delegate = self;
nextTextField.inputAccessoryView = self.myToolbar;
nextTextField.delegate = self;

 

示例图:


inputAccessoryView的使用

你可能感兴趣的:(ios,iPhone)