If you add spacers in between each item, the spacing should work itself out. In your case you might like to put a spacer either side of the two buttons and one in between. You can do this like so: UIBarButtonItem *spacer = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil; NSArray *items = NSArray alloc initWithObjects: spacer, barButton1, spacer, barButton2, spacer, nil; spacer release Note that you can also use UIBarButtonSystemItemFixedSpace but you would need to specify it's 'width' property explicitly.
Whereas UIBarButtonSystemItemFlexibleSpace works this out for you it would seem.
If you add spacers in between each item, the spacing should work itself out. In your case you might like to put a spacer either side of the two buttons and one in between. You can do this like so: UIBarButtonItem *spacer = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil; NSArray *items = NSArray alloc initWithObjects: spacer, barButton1, spacer, barButton2, spacer, nil; spacer release; Note that you can also use UIBarButtonSystemItemFixedSpace but you would need to specify it's 'width' property explicitly.
Whereas UIBarButtonSystemItemFlexibleSpace works this out for you it would seem.
I have solved this problem, you should use flexible item before and after each button. UIBarButtonItem *flexibleSpace = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil; Just add the flexibleSpace to your array of items which gonna be set in toolbar. P.s.
I have almost kill myself before get rid of this and have tried all type of solutions including using of other bars instead of UIToolBar.
This doesn't with the spacing on the left and right, only inter-button spacing. – Joshua Weinberg Feb 15 at 23:36.
Well, this is a really old question, but I just ran into the same issue and managed to solve it. The magic password is setting the UIBarButtonItem style to be UIBarButtonItemStyleBordered. UIBarButtonItem *item = UIBarButtonItem alloc initWithCustomView:aView; item.
Style = UIBarButtonItemStyleBordered; Thats it...
I met the same issue. Finally, I solved this by subclassing UIToolbar and override the layout subviews method. - (void)layoutSubviews { super layoutSubviews; if (leftItem_ && leftItem_.
CustomView && leftItem_. CustomView isKindOfClass:UIButton class) { CGRect newFrame = leftItem_.customView. Frame; newFrame.origin.
X = 0; // reset the original point x to 0; default is 12, wired number leftItem_.customView. Frame = newFrame; } if (rightItem_ && rightItem_. CustomView && rightItem_.
CustomView isKindOfClass:UIButton class) { CGRect newFrame = rightItem_.customView. Frame; newFrame.origin. X = self.frame.size.
Width - CGRectGetWidth(newFrame); rightItem_.customView. Frame = newFrame; } }.
UIBarButtonItem *barButton1,*barButton2; barButton1 = UIBarButtonItem alloc initWithImage:UIImage imageNamed:@"image1. Png" style:UIBarButtonItemStylePlain target:self action:@selector(action:); barButton2 = UIBarButtonItem alloc initWithImage:UIImage imageNamed:@"bart_tb. Png" style:UIBarButtonItemStylePlain target:self action:@selector(action:); NSArray *items = NSArray alloc initWithObjects: barButton1, barButton2, nil; barButton1 release; barButton2 release; self.
Toolbar setItems:items animated:NO; items release; Do it like that.. and if you want to change the width of the buttons, set the width property of the UIBarButtonItem objects. The default value of width is 0, which makes it big enough exactly to fit its image/title. Hope that helps.
Thanks for your quick reply. Unfortunately this didn't work for me. The images appear as white boxes (whereas they appear correctly with the above method) and the gaps are still there, even when I change the UIBarButtonItem width property.
I checked again to make sure I'm not doing anything else with the toolbar that could be messing things up and I'm not. – greg Aug 2 '09 at 23:21 I edited this a bit later, make sure you're using the UIImage imageNamed:@"; Even if you're still having a problem, the way this should be done is like I showed you, not with a UIButton. If you have two barbuttonitems, I think they will go on either end of the toolbar, I think they automatically space themselves out.
You might want to try using an IB file to get your interface all laid out and then code it, making sure to set all the properties as they are in the nib. – Mk12 Aug 3 '09 at 5:34 Yep, I'm using UIImage imageNamed.... The problem is that this method takes only the alpha of the image and I want to use color images. The second issue is that the gaps still occur even when I add five items, causing the 5th to end up partly off the right side of the toolbar.Is there any way to remove these gaps altogether?
– greg Aug 5 '09 at 7:06 Its hard to answer when I don't really see what you're talking about.. could you show me a picture of what it looks like? – Mk12 Aug 5 '09 at 7:16 It is written on the documentations that the buttons just considers the alpha channel, not the colors. – Digital Robot Sep 26 '09 at 15:19.
It is possible to add a fixed space item with a negative width between the items to compensate the spacing. UIBarButtonItem *fixedSpace = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil autorelease; fixedSpace. Width = -12.0f.
If you're looking for is to layout UIBarButtonItems with less than the default or even 0 vertical spacing(like me) that's automaticall done for you buy UIToolBar; Here's what I would recommend: UIToolBar layouts it's items privately. Apple engineers will never really expect developers to overwrite that. Using a fixed spaces to overwrite the default 10Point horizontal spacing is not enough.
Since UIToolbar layout its items at least 10 point apart, you set the width of these UIBarButtonItems to -10 in order to get no spacing as the following code shows: CGFloat toolbarHeight = 44.0; CGRect toolbarFrame = CGRectMake(0,0, self.view.bounds.size. Width, toolbarHeight); UIToolbar *toolbar = UIToolbar alloc initWithFrame:toolbarFrame; UIBarButtonItem* noSpace = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil autorelease; UIBarButtonItem* noSpace1 = UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil autorelease; noSpace. Width = -10.0; noSpace1.
Width = -10.0; toolbar setItems:NSArray arrayWithObjects: UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:nil autorelease, noSpace, UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil autorelease, noSpace1, UIBarButtonItem alloc initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:nil action:nil autorelease , nil.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.