0

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.

Community
  • 1
  • 1
Krzysztof Romanowski
  • 2,164
  • 2
  • 20
  • 29

3 Answers3

2

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.

LombaX
  • 17,265
  • 5
  • 52
  • 77
1

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.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • The issue here will be mimicking the look/feel/behavior of a UIBarButtonItem with a UIButton. Always a PITA. – TomSwift Aug 09 '13 at 17:42
0

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...

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • I need buttons to be custom views. I use negative width for button which removes right edge margin. Placing such button between my custom buttons will not have any effect. – Krzysztof Romanowski Aug 13 '13 at 11:18
  • Actually it will have effect. I've used this trick to space custom buttons and it works fine. – TomSwift Aug 13 '13 at 14:14