添加导航栏按钮

UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];
listButton.frame = CGRectMake(0, 0, 22, 22);
[listButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[listButton addTarget:self action:@selector(onRightBarButtonItemClick) forControlEvents:UIControlEventTouchUpInside];

UIButton* searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
searchButton.frame = CGRectMake(0, 0, 22, 22);
[searchButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
[searchButton addTarget:self action:@selector(onRightBarButtonItemClick) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItems = @[[[UIBarButtonItem alloc] initWithCustomView:searchButton],
                                            [[UIBarButtonItem alloc] initWithCustomView:listButton]];

你可能感兴趣的:(添加导航栏按钮)