如何在工具栏中心显示按钮? [英] How to show button in center of toolbar?
问题描述
我想在工具栏的顶部和中心显示按钮。我设置了UIBarButtonItem的图像,但它没有给出如下图所示的预期结果。
I want to show button on top of and in center of Toolbar. I set the image of UIBarButtonItem but it does not give desired result as given in below image.
我可以添加菜单并找到我
I am able to add Menu and Locate Me
但无法添加请求按钮,如图所示。
请求BUtton是一张图片,当我设置时它被拉伸的UIBarButtonItem图像
Request BUtton is an image and when I set it the UIBarButtonItem image it gets stretched
请帮助
这就是我所做的。
This is what I have done.
但是我想做这个。正如您可以看到,在我的解决方案中,请求按钮位于工具栏下方,在下面的图片请求按钮位于顶部。
But I want to do this. as You can see that in my solution Request button is under toolbar and in the below pic Request button is on top.
推荐答案
只需将 UIBarButtonItem
与 FlexibleSpace
添加到这两个按钮的两侧,如下图所示。 。
just add UIBarButtonItem
with FlexibleSpace
to both side of these two button like bellow..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
查看带有两个按钮的所有代码..
See all code with two buttons..
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *locateMe = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(locateMe:)];
UIBarButtonItem *request = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(request:)];
UIBarButtonItem *menu = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStylePlain target:self action:@selector(menu:)];
NSArray *toolbarItems = [NSArray arrayWithObjects:locateMe,flexibleSpace,request , flexibleSpace, menu];
[toolBar setItems:toolbarItems animated:NO];
从 XIB
您也可以设置此 UIBarButtonSystemItemFlexibleSpace
如下图所示..
From XIB
you can also set this UIBarButtonSystemItemFlexibleSpace
like in bellow image..
更新:您想在UIToolBar上添加带有该图像的请求按钮然后在 UIView $ c $上添加
UIToolBar
之后再带上 UIImageView
和按钮c>像bellow ..
UPDATE: you want to Add that request button with that image on UIToolBar then just bring that UIImageView
and button after add UIToolBar
on the UIView
like bellow..
[self.view bringSubviewToFront:imgView];
[self.view bringSubviewToFront:btnRequest];
这篇关于如何在工具栏中心显示按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!