0

I added a UIToolBar from Interface builder, then dragged 2 UIBarButtonItem's. Now i need to add an image to it. So i selected the barButtonItem and selected the image using Interfacebuilder.

I only get a White image, with no curvy edge. My image is as follows. I don't see that image, but instead i see a white rectangle.

How do i prevent this. Can someone tell me whats wrong, and provide me with a working solution.

my bar button enter image description here

Illep
  • 16,375
  • 46
  • 171
  • 302
  • What is the size (dimension) of the image you want to set as the background of the UIBarButtonItem? Maybe it is because, the image is too big to fit. – Sierra Alpha Feb 14 '12 at 15:08
  • But, it should not show a white background. the size of the button is 100X35. If you have done this could you kindly share your solution. I am stuck in this for hours – Illep Feb 14 '12 at 15:17
  • I'd look @ this question, not IB, but it does the job - http://stackoverflow.com/questions/664930/uibarbuttonitem-with-color – barfoon Feb 14 '12 at 18:19
  • Yes, that did but there's another problem with that which i can't use it in my project. I have tried this before, in fact the above image is from that SO question (i only changed the colour of it) – Illep Feb 14 '12 at 22:51

2 Answers2

0

You should drag an "Image View" on to your layout and specify the image in that - that worked for me, but I'm no xcode guru.

Hope that helps, Paul

Paul Higgins
  • 1,126
  • 1
  • 14
  • 15
0

If you go to iOS Human Interface Guidelines you will see the specifications for icons and buttons. This is my experience, for the best result you'd better create a specific icon (image) for UIBarButtonItem. If you still want to use an image, that doesn't follow the UIBarButtonItem guide, my approach is:

  1. Add a generic UIButton instance to your view. Drag it from the list on the right to the view, not to the ToolBar or navBar.
  2. Customize it with the image, i.e. from the Inspector, set the image or background image, or set it to custom style, bordered, etc.
  3. Drag it to the toolBar, and XCode will adjust it. Again, it does not always guarantee the best result, but it does what you want.

I hope it helps.

Sierra Alpha
  • 3,707
  • 4
  • 23
  • 36