UIImage in setBackBarButtonItem in UINavigationBar iphone

I add an image to the BackBarButtonItem navigation bar, the image hits the button, but the image does not scale to fill in what would be the problem.

Here is the code I'm using and it displays as follows.

UIImage *backImage = [UIImage imageNamed:@"back.png"]; UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithImage:backImage style:UIBarButtonItemStylePlain target:self action:@selector(backAction)]; [self.navigationItem setBackBarButtonItem: newBackButton]; [newBackButton release]; [backImage release]; 

enter image description here

In fact, it should look like below.

enter image description here

Thanks!

+4
source share
2 answers
 [self.navigationItem setHidesBackButton:YES]; [self.navigationItem setLeftBarButtonItem:newBackButton]; 

Try the following :)!

+2
source
 problem is your image size.check it! You can also use //custom back button button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal]; [button addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside]; [button setFrame:CGRectMake(-2, 0, 52, 30)]; UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:button]; self.navigationItem.leftBarButtonItem = btnItem; [btnItem release]; } 
0
source

Source: https://habr.com/ru/post/1342622/


All Articles