Separator between toolbar items in UIToolbar
Asked Answered
C

4

12

How to add a separator between buttons in a UIToolbar?

Sample image is shown in the below link

enter image description here

Craniology answered 7/2, 2012 at 17:5 Comment(0)
E
6

I can think of two ways :

(a) You could make them very thin toolbar buttons with user interaction disabled.

(b) Your other choice would be to implement your own toolbar. I'd try (a) first ;)

Elusive answered 7/2, 2012 at 18:19 Comment(1)
I had to do that in the past and the easiest way, under iOS 5 at least, was to use method (a). Using the new custom appearance api, setting a background image and setting the button width to 1px, the effect was very convincing. You can then use flexible spacers as usual to keep everything aligned just right.Polygyny
H
16

I did it with a custom view button, with a 1 pixel wide background:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1, 44)];
label.backgroundColor = [UIColor whiteColor];

UIBarButtonItem *divider = [[UIBarButtonItem alloc] initWithCustomView:label];
// Add button to array of toolbar items
[items addObject:divider];
// Or set items directly:
//toolbar.items = [NSArray arrayWithObject:divider];
label.text = @"";
Honaker answered 2/5, 2013 at 17:28 Comment(0)
E
6

I can think of two ways :

(a) You could make them very thin toolbar buttons with user interaction disabled.

(b) Your other choice would be to implement your own toolbar. I'd try (a) first ;)

Elusive answered 7/2, 2012 at 18:19 Comment(1)
I had to do that in the past and the easiest way, under iOS 5 at least, was to use method (a). Using the new custom appearance api, setting a background image and setting the button width to 1px, the effect was very convincing. You can then use flexible spacers as usual to keep everything aligned just right.Polygyny
E
1

You can also make a toolbar button and set the Title = |

Estrone answered 14/10, 2017 at 17:24 Comment(0)
B
0

If yo want a clean, simple layout I would prefer a very thin image with this separator in it. Then you can add fix distances between your normal button, the separator image button (user interaction disabled) and the next button.

Baccalaureate answered 7/2, 2012 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.