5

How do I add a UIBarButtonItem to a UIToolbar with both text and an image in it? Take a look at the example image I show. It's exactly what I'm trying to do.

Here's the image

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194

4 Answers4

6

First of all create a UIButton, with Image and title.

Then add that Button to BarButtonItem

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:customButton];
Satya
  • 3,320
  • 1
  • 20
  • 19
  • Yes, but does that imply that I have to completely style the button to look exactly like a normal UIBarButton? The advantage of using a standard UIBarButtonItem is to get the shine in the middle of the button. – Ethan Allen Oct 05 '11 at 06:40
  • @Ethan Allen :For that you need to design the button image as like the barbuttonItem. Every one will do like that only. – Satya Oct 05 '11 at 06:43
1

add custom buttom to toolbar set this property to that button add label on button for text

button.contentHorizontalAlignment =  UIControlContentHorizontalAlignmentLeft;
Narayana Rao Routhu
  • 6,303
  • 27
  • 42
0

You should create UIView with UILabel and UIImage as subviews. Then create UIBarButtonItem with custom view:

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:customView];
Nekto
  • 17,837
  • 1
  • 55
  • 65
0

A couple of reference link will guide you to how to implement UIBarButtonItem to a UIToolbar with text and an image.... You just modify the code as per your requirements.

  1. UIToolbar UIBarButtonItem with both image and title has very dim text

  2. add image to UIBarButtonItem for UIToolbar

Community
  • 1
  • 1
alloc_iNit
  • 5,173
  • 2
  • 26
  • 54