iOS – Set Custom UinaVigationBar Image for Left and SOW buttons

This is what I have on the storyboard:

I want to change two button images. I have a 13×46 image, but I I have encountered a problem when using it as the image of the button. I have been looking for some codes, but I am not very successful with them.
Any ideas?

This is a very simple thing, just alloc / initWith Image a few bar button items, and then Apply them.

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector (someMethod)];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod)];

[[self navigationItem] setLeftBarButtonItem:leftItem];
[[self navigationItem] setRightBarButtonItem:rightItem];

This of course assumes that you are actually using a navigation controller. If you only have one Drag and drop navigation bar in the interface builder, then you need to create an IBOutlet for the navigation bar, link it, and then use the following content:

UINavigationItem *item = [[ UINavigationItem alloc] initWithTitle:@"Title"];
[item setRightBarButtonItem:rightItem];
[myNavBar pushNavigationItem:item animated:NO];

Add a flexible space between.

This is what I have on the storyboard:

I want to change the two button images. I have a 13×46 image, but I am having trouble using it as the image of the button. I have been looking for some codes, but I am not very successful with them.
Any ideas?

This is a very simple thing, just alloc / initWith Image a few bar button items, and then apply them.

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod)];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage"] style:UIBarButtonItemStyleBordered target:self action:@selector(someMethod)];

[[self navigationItem] setLeftBarButtonItem:leftItem];
[[self navigationItem] setRightBarButtonItem:rightItem];

This of course assumes that you are actually using a navigation controller. If you only have one navigation bar that you drag and drop in the interface builder, then you You need to create an IBOutlet for the navigation bar, link it, and use the following content:

UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Title"];< br />[item setRightBarButtonItem:rightItem];
[myNavBar pushNavigationItem:item animated:NO];

You may need to add a flexible space between the two.

< /p>

Leave a Comment

Your email address will not be published.