I have made at least 10 buttons for my navigation bar, but it never seems to work right. The rounded edges get pixelated. I cant have that in an app, so can anyone tell me how t
Try this code:
UIImage *backButtonImage = [UIImage imageNamed:@"backButton.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBackBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = customBackBarItem;
and, the back method:
-(void)back {
[self.navigationController popViewControllerAnimated:YES];
}
The code above just set the image for normal state. You can also set highlighted state for a better appearance. Add some codes Like:
UIImage *backButtonImageHighlighted = [UIImage imageNamed:@"backButtonHighlighted.png"];
[backButton setImage:backButtonImageHighlighted forState:UIControlStateHighlighted];