Arun kumar
Arun kumar

Reputation: 55

navigating bar item icon not showing correctly

navigation bar item icon colour blue or single colour. Not able to render the original image in the navigation bar. already tried the option render as original from the Assets.xcassets attributes inspector

want to use thisimage

but sadly when tried selecting through storyboard it shows it in only one single colour square i.e only blue , white or any other colour. how can i use the original image for bar button item.

Upvotes: 0

Views: 722

Answers (2)

DJ1
DJ1

Reputation: 944

Try this ...

This one works for me...

UIButton *btnChat = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
[btnChat setBackgroundImage:[UIImage imageNamed:@"chat_icon.png"] forState:UIControlStateNormal];
[btnChat addTarget:self action:@selector(chatButtonClicked) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btnChat];

Upvotes: 0

iPatel
iPatel

Reputation: 47089

As per my understanding, you want to set image on navigation bar right ? Hope below code will wok for you,

UIImage *myImage = [UIImage imageNamed:@"myImageName.png"];
myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc] initWithImage:myImage style:UIBarButtonItemStylePlain target:self action:@selector(menuObject:)];
self.navigationItem.leftBarButtonItem = searchButton;

Upvotes: 1

Related Questions