0

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 to make a good icon that looks like an apple one? Also what is the proper size? The code in the app for the button is

UIButton *backbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backbtn.frame = CGRectMake(0, 0, 55, 30);
    [backbtn setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];

    [backbtn addTarget:self action:@selector(goBackOne) forControlEvents:UIControlEventTouchUpInside]; forState:UIControlStateNormal ];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbtn];//set new button

    self.navigationItem.hidesBackButton = YES;//hide original back button
4

1 回答 1

0

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];
于 2013-07-28T03:12:28.643 回答