Add Image For UIBarButtonItem From xib File- Objective C - iphone

I am trying to add an image for my UIBarButtonItem from the xib file itself. However, I am getting a grey coloured button which is of the same size and shape as that of my image. How can I display the image correctly and directly from my xib file itself without going into the writing of code manually ?? The button is present on a toolbar. Thanks and Regards.

Use UIButton beside of barButtonItem. It will automatically make a barButton and a Button inside of that.
then you need to change batButtonItem text to "" and change the Image of UIButton
as I tested it will work and show your pic beside of barButtonItem

Related

Button text doesn't visible after adding an image to its image property in iphone

I have a button.I have added an image to its image property and also to its background image property.Now it only display the button with added images and can't see button text.What is the reason.
Thanks for the help.
Setting the background image is fine but when you set the button.image property, it is overlaid over the textfield that the button has so you do not want to add an image to that property if you plan on using the buttons text.
you have to play with the EdgeInset property of the UIButton to properly align the content of the button (title an image)
use setBackgroundImage:forState: method of UIButton
You have to add image to background if you want to add title later or else use image with text.
Put image in background image just below image if you do it through nib

adding icon to uisearchbar

Can I add an icon to the uisearch bar like this
Ya you can add the icon if you are talking about the image on left then just add a image and if you are talking about the image to the right. which i think is a search button then you can add a button and do your search code on it.
ok so what you have to do now is, i am assuming that you want to implement the search bar with icon on the toolbar. just add a UIButton and in the IB select the UIButton and go to attribute inspector and set the type to custom.
Now when you add the image to it(set the background property to the image you have selected)
By doing this you can easily resize your image.(means just resize the button, it will automatically resize your image too).
hope this will work.

UIBarButtonItem Taking Entire Width of UIToolbar

I have a UIToolbar with a UIBarButtonItem that I created in Interface Builder. The UIBarButtonItem is a bordered button that contains a custom image.
The button takes up the entire length of the toolbar. I have tried using different images, changing the width of the button... I don't know what else to do. It stretches across the entire toolbar.
If I use one the provided "Identifiers" (camera, trash, compose...) the button appears a normal size.
How it looks in Interface Builder
How it looks when I run it on the iPhone
SOLUTION
After some more tinkering, here is what I found: if I create a new UIToolbar and add custom image to the UIBarButtonItem, it works fine - but as soon as I connect the UIBarButtonItem to an IBOutlet, it goes large. I had to then specify the UIBarButtonItem's width in the code, via the IBOutlet.
Try adding a UIBarButtonSystemItemFlexibleSpace on the right of the camera bordered item.
I'm not an expert, but I think it might have to do with how the frame is defined in the "sizing inspector", could you maybe show a screenshot of the settings?

in iPhone SDK How to change the color of BarButton Item

How to change color of leftBarButtonItem of UIBarButtonItem in NavigationBar?
if I am trying to set image in bar button through interfaceBuilder it shows border on image in bar button so is there any specific size for image for bar button or how to set image with-out showing border in it ?
If I am adding BarButton dynamically it doesn"t appear while running App
and if I am adding leftbarButton in xib only and connecting outlets then the leftbar button become visible but I am not able to assign customview view to it my ultimate goal is to change the color of left bar buttton
Please Help and Suggest,
Thanks
Create the bar buttom item with a custom view using -[UIBarButtonItem initWithCustomView:]. That way, you have all the control you want over the appearance.
I think you can use:
- (id)initWithImage:(UIImage *)image style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action
You can set custom image for your bar button.
If it's just the colour you want to change, add the button to the bar and then set the tint colour of the bar (see docs on UINavigationBar or UIToolBar). This of course changes the bar colour as well as the button however, but it's good practice (UI consistency wise) to use the same colour for UIBarButtonItems and their bars especially if you're using out-of-the-box buttons.

UIButton doesn't appear on UIToolbar

I have a UIToolbar where I have dragged a UIButton. When I set the button properties to Custom, and assign an image (or background image) the graphics don't appear. However, when I give it a custom text, the text will appear. Why is it that the images don't appear?
Are you sure the image is present in your bundle/project?
Are you setting the button's image for UIControlStateNormal?