更新时间:2023-02-26 12:35:20
是否有理由不能只使用 UIToolbar
?
Is there a reason you couldn't just use a UIToolbar
?
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0.0, 0.0, 320.0, 44.0)];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCancel
target: self
action: @selector(cancel)];
UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace
target: nil
action: nil];
UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemDone
target: self
action: @selector(done)];
NSMutableArray* toolbarItems = [NSMutableArray array];
[toolbarItems addObject:cancelButton];
[toolbarItems addObject:space];
[toolbarItems addObject:doneButton];
[cancelButton release];
[doneButton release];
[space release];
toolbar.items = toolbarItems;
然后只需将工具栏添加到视图。请确保正确定位并实施完成
和取消
选择器。
Then just add the toolbar to your view. Make sure to size it correctly and implement the done
and cancel
selectors.