简体   繁体   中英

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 this image

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

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;

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM