在自定義按鈕使用自定義圖片。然後我想設置標題時弄不上。
代碼:
- (void)viewDidLoad
{
UIImage *backButtonImage = [UIImage imageNamed:@"button.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor colorWithRed:0.49 green:0 blue:0 alpha:1] forState:UIControlStateNormal];
[backButton setTitle:@"DONE" forState:UIControlStateNormal];
backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
[backButton addTarget:self action:@selector(goBackOne) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.hidesBackButton = YES;//hide original back button
}
效果圖片:
[backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];