我是 iOS 编程新手,我想知道是否可以将 4 个条形按钮放入UINavigationBar
?我尝试了一些在堆栈溢出时发现的方法,但buttons
位置不相等。
这是一个示例屏幕截图
.
我用来编码导航栏的方法是:
UIToolBar *tools = [[UIToolBar alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
UIImage *backImage = [UIImage imagedName:@"backIcon.png"];
UIImage *shareImage = [UIImage imagedName:@"shareIcon.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backImage forState:UIControlStateNormal];
// create the button and assign the image to the leftsidebutton
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backImage.size.width, backImage.size.height);
[backButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
[shareButton setImage:shareImage forState:UIControlStateNormal];
shareButton.frame = CGRectMake(0, 0, shareImage.size.width, shareImage.size.height);
//create space between the buttons
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL];
UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
UIBarButtonItem *shareBarButton = [[UIBarButtonItem alloc] initWithCustomView:shareButton];
self.navigationItem.hidesBackButton = YES;
NSArray *leftActionButtonItems = @[customBarButton, bi, shareBarButton];
[tools setItems:leftActionButtonItems animated:NO];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
我做了同样的事情,rightBarButtonItem
但效果不太好。
任何帮助将不胜感激!谢谢!