我的问题很简单:如何更改 UIImagePickerController 导航栏中栏按钮的更改标题?我为 UIImagePickerController 创建了控制器(由按钮上的压力触发),然后尝试修改其属性:
- (IBAction)chooseFromRoll:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.navigationBar.tintColor = [UIColor colorWithRed:0.42 green:0.18 blue:0.66 alpha:1.0];
//imagePicker.navigationItem.title = @"Scegli foto profilo";
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = NO;
[imagePicker.navigationController.navigationItem.rightBarButtonItem setTitle:@"Annulla"];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
但没有任何改变,只有导航栏被正确修改。
这是函数 willShowViewController 的代码:
- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.textAlignment = 2;
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, label.frame.size.width-200,label.frame.size.height);
label.adjustsFontSizeToFitWidth = YES;
label.font = [UIFont fontWithName:@"Futura" size:15.0];
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:@"Scegli foto profilo"];
[navigationController.navigationBar.topItem setTitleView:label.viewForBaselineLayout];
[navigationController.navigationBar.topItem.rightBarButtonItem setTitle:@"Annulla"];
}
你能告诉我哪里错了吗?
谢谢