Piyush Patel
Piyush Patel

Reputation: 1825

UIImage in setBackBarButtonItem in UINavigationBar iphone

I am adding image in BackBarButtonItem of navigation bar, image gets in button but image is not scale to fill what would be the issue.

Here is the code i am using and it displays in following way.

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

Actually it should look like, below image.

enter image description here

Thanks!

Upvotes: 4

Views: 2480

Answers (2)

cutsoy
cutsoy

Reputation: 10251

[self.navigationItem setHidesBackButton:YES];
[self.navigationItem setLeftBarButtonItem:newBackButton];

Try this :)!

Upvotes: 2

Swastik
Swastik

Reputation: 2425

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

Upvotes: 0

Related Questions