Common UIToolbar for the required pages - Xcode 8.3 - swift

Please suggest that how we can create common UIToolbar(with bar items) for the required pages?
I know that we can add custom UIBarButtonItem in each view controller.

Assuming you use storyboard. First, drag a UIToolBar item to your storyboard.
Next, set up the location of the tool bar. In my example, I put it on the bottom with padding 0 to left, right and bottom. The height is set to be 44
Finally, drag as many Bar Button Item as you want to your tool bar, and then add spaces between them. You can either use fixed length spaces, or the flexible ones (which are used in this example) by simply drag them between the bar button items.

Related

How to reduce spacing between items in Navigation Bar?

In my Swift project I have 2 items on Right Bar but I see that spacing between them is too big. How to reduce it? Or how to move pen icon closer to time icon?
You're not in control of the spacing of separate bar button items. You could make a single bar button item containing a custom view holding two buttons, and then you would be in control of their spacing.

How to add two custom rightBarButtonItems without a margin between them?

I create UIToolbar with interface builder and want to add two custom right buttons, but without a space between them. I don't want solution to reset a margin from the right edge, because I found it here but want only reset margin between buttons.
How should I do this?
Thanks.
Instead of a button, use an UISegmentedControl and set its momentary property to yes.
Add one segment for each button you want (in this case two segments)
Then add an IBAction and use a switch to know what index has been selected.
Index 0 first button, index 1 second button.
Create a bar button item with a custom view where that custom view has 2 UIButtons as subviews. In this way you can exactly size and position the buttons as you require.
To adjust space between UIBarButtonItem's you can use a UIBarButtonItem with style UIBarButtonSystemItemFixedSpace and setting its width property.
You can move items closer to eachother than the default spacing by setting the width of the spacer item to be a negative value.
One thing to consider is future-proofing whichever solution you choose. Buttons in iOS6 have nice borders and shading. They may not in the near future...

Add space to toolbar in iPhone

I am new to iPhone,
I have added a toolbar in my .xib file and then added 5 BarbuttonItem to the toolbar,
see snapshot:
you can see bar buttons on toolbar, but there is no spaces between them.. what i want is.. there should be sufficient space between all button like search bar to placed at extreme right, a and A should be in the middle of tool bar.
when i try to drag search bar at extreme right it drags properly but on living of mouse click search bar again comes to it's original position.
How to solve this ?
Any help will be appriciated.
In the Objects panel there are two UIBarButtonItem subclasses named Fixed Space Bar Button Item and Flexible Space Bar Button Item. You need to use those two to adjust your spaces.

How to specify width, flexible space and/or position between UITabBarItems in UITabBar?

I am working on a project when client wants UITabBar lookalike toolbar (icons and titles) at the bottom of some views.
The tab bar needs to have 1 item at the left, empty space, and then 2 items at the right.
Do I have to use 2 extra UITabBarItems (and put them at second and third position) and hide and disable them to accomplish this, or is there a more straightforward solution?
I would like to not to use UIToolBar for this as customizing its height is a pain and causes unexpected behavior in some cases (especially when one uses modal view controllers).
I think you have the right idea. Customizing UITabBar to do stuff out of the ordinary is often quite hard and it is better to just write your own. But in your case you should be able to just as you proposed. One way would be to add the view controllers directly in IB and then set title to an empty string and untick enabled for the second and third view controller.

Can I add two right-hand buttons to a UINavigationBar?

I would like to be able to have a UINavigationBar with a left-hand UIBarButtonItem, two right-hand UIBarButtonItems, and a title.
I have resorted to using a UIToolBar to simulate this, but the toolbar looks slightly different than the UINavigationBar, and it also won't bevel UIBarButtonSystemItems.
Is there a way to make a UINavigationBar with three UIBarButtonItems?
There's no way to do this using all native graphics. However, if you're willing to get your hands a little dirty in Acorn or Photoshop, you can create your buttons images there, and then add several buttons to a UIView, encase that in a UIBarBUttonItem, and set it to be the leftBarButtonItem.
This question tackles the item as well: How to add 2 buttons into the UINavigationbar on the right side without IB?
I posted code to add two buttons to the right of the navigationBar. You can set barStyle = -1 instead of subclassing UIToolbar.
Since iOS5 it's easily possible ( https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/instm/UINavigationItem/setRightBarButtonItems:animated: ) :
setRightBarButtonItems:animated:
Sets the right bar button items, optionally animating the transition to the new items.
- (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated
Discussion
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.
Availability
Available in iOS 5.0 and later.
Declared In
UINavigationBar.h