我想在rightBarButtonItem中添加三个按钮,但它只显示两个。
我还尝试在self.view中添加UIView(视图中的按钮),但它位于导航下方。
答案 0 :(得分:1)
像这样:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addButton:)];
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(showAllButton:)];
UIBarButtonItem *searchButton2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(showAllButton:)];
self.navigationItem.rightBarButtonItems = @[searchButton, addButton, searchButton2];
答案 1 :(得分:0)
YourViewontroller.h
UIView *view_navigation;
viewcontroller.m
- (void)viewDidLoad
{
view_navigation = [[UIView alloc]initWithFrame:CGRectMake(200, 5, 100, 40)];
view_navigation.backgroundColor = [UIColor clearColor];
UIButton *add_button = [UIButton buttonWithType:UIButtonTypeCustom];
[add_button setBackgroundImage:[UIImage imageNamed:@"Add-icon.png"] forState:UIControlStateNormal];
[add_button addTarget:self action:@selector(Add_Student:) forControlEvents:UIControlEventTouchUpInside];
[add_button.imageView setContentMode:UIViewContentModeScaleToFill];
[add_button setFrame:CGRectMake(0, 8, 25, 25)];
[view_navigation addSubview:add_button];
UIButton *Remove_button = [UIButton buttonWithType:UIButtonTypeCustom];
[Remove_button setBackgroundImage:[UIImage imageNamed:@"Delete_icon.jpeg"] forState:UIControlStateNormal];
[Remove_button addTarget:self action:@selector(Remove_Student:) forControlEvents:UIControlEventTouchUpInside];
[Remove_button.imageView setContentMode:UIViewContentModeScaleToFill];
[Remove_button setFrame:CGRectMake(40, 8, 25, 25)];
[view_navigation addSubview:Remove_button];
UIButton *Edit_button = [UIButton buttonWithType:UIButtonTypeCustom];
[Edit_button setBackgroundImage:[UIImage imageNamed:@"Edit_icon.jpeg"] forState:UIControlStateNormal];
[Edit_button addTarget:self action:@selector(Edit_Student:) forControlEvents:UIControlEventTouchUpInside];
[Edit_button.imageView setContentMode:UIViewContentModeScaleToFill];
[Edit_button setFrame:CGRectMake(80, 8, 25, 25)];
[view_navigation addSubview:Edit_button];
[self.navigationController.navigationBar addSubview:view_navigation];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillDisappear:(BOOL)animated
{
[view_navigation removeFromSuperview];
[super viewWillDisappear:animated];
}