开发者

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开发者_JS百科 target:self action:@selector(backAction)];
[self.navigationItem setBackBarButtonItem: newBackButton];
[newBackButton release];
[backImage release];

UIImage in setBackBarButtonItem in UINavigationBar iphone

Actually it should look like, below image.

UIImage in setBackBarButtonItem in UINavigationBar iphone

Thanks!


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

Try this :)!


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜