How to show the button in the center of the toolbar?

I want to show the button on top and in the center of the toolbar. I installed the UIBarButtonItem image, but it does not give the desired result, as shown below.

I can add a menu and find me

but failed to add a query button , as shown in Figure ..

The BUtton request is an image, and when I set its image to UIBarButtonItem, it is stretched

please, help

Here is what I did. enter image description here

But I want to do it. as you can see, in my button the “Request for Request” button is located under the toolbar, and in the button “Request” below it is located on the top. enter image description here

+7
ios iphone ipad toolbar
source share
2 answers

just add the UIBarButtonItem with FlexibleSpace to both sides of these two buttons, as shown below.

 UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

View 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]; 

From XIB you can also set this UIBarButtonSystemItemFlexibleSpace , as shown below.

enter image description here

UPDATE: you want to add this request button with this image to the UIToolBar, and then just bring this UIImageView and button after adding the UIToolBar to the UIView , as shown below.

 [self.view bringSubviewToFront:imgView]; [self.view bringSubviewToFront:btnRequest]; 
+18
source share

From Nib, use a flexible space element on a UIToolbar object. as below Image: -

enter image description here

To add a central Bigger button, then ToolBar Hight, then check this below Demo and use your category to complete this task. Just drag the image into the demo and change the image name to CenterButtonIconPaw.png and check: -

https://github.com/el-eleven/EEToolbarCenterButton

using your image, which I made as you want. It looks like your Need: -

enter image description here

+3
source share

All Articles