更改栏按钮的称号的UIImagePickerController的导航栏 [英] Change title of bar button in UIImagePickerController's navigation bar

查看:377
本文介绍了更改栏按钮的称号的UIImagePickerController的导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单:如何更改栏按钮的变化称号的UIImagePickerController的导航栏?
我创建的UIImagePickerController控制器(由pressure到一个按钮触发),然后试图修改它的属性:

my question is simple: how can i change change title of bar button in UIImagePickerController's navigation bar? I created the controller for UIImagePickerController (triggered by the pressure onto a button) and then tried to modify its properties:

- (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];
    }
}

但没有任何改变,只是导航栏被正确修改。

but nothing changed, only navigation bar was correctly modified.

这里的code的功能willShowViewController:

Here's the code for function 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"];



}

你能告诉我哪来的错误?

can you tell me where's the mistake?

感谢

推荐答案

下面是twicking导航栏的标题在UIImage的选择器中code片段。

Here is a code snippet for twicking the title of the navigation bar in uiimage picker.

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *ipcNavBarTopItem;

// add done button to right side of nav bar
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Photos"
                                                               style:UIBarButtonItemStylePlain 
                                                              target:self 
                                                              action:@selector(saveImages:)];

UINavigationBar *bar = navigationController.navigationBar;
[bar setHidden:NO];
ipcNavBarTopItem = bar.topItem;
ipcNavBarTopItem.title = @"Photos";
ipcNavBarTopItem.rightBarButtonItem = doneButton;
}

希望这会帮助你。

Hope this would help you out.

编辑:

在回答第一个问题是肯定的,你可以使用IBAction为或只是使用我上面提供的创建按钮的方法,既要工作。如果您使用的是无为而治,一定要声明您在它控制器,以便使它看起来并从action方法中驳回。答案如果你想改变是当从相册图片选择器psented那么你需要创建一个新的子视图,并流行起来,让用户$ P $ presented视图的标题第二个问题选择所需的图像,然后您可以更改标题我做到了上面的方法。漫长的过程,我不会推荐它。回答第三个问题,请尝试使用在那里你宣布你的按钮以下code片段,

the answer to first question is yes you can use the ibaction or just use the method i provided above to create the button, both should work. if you are using inaction, make sure you declare you controller within it so you can make it appear and dismiss it from within the action method. the answer to the second question if you want to change the title of the view that is presented when image picker from the photo album is presented then you need to create a new subview and pop it up to allow the user to select the desired image then you can change the title the way i did it above. lengthy process, i would not recommend it. the answer to the third question, try using the following code snippet where you declare your button,

[btn.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];

其中BTN是你的按钮的名称,并可以修改字体名称和大小。我希望我的回答可以帮助你。好运气,让我知道如果你需要更多的帮助。

where the btn is the name of your button and you can modify the font name and the size. i hope my answers can help you. good luck and let me know if you need any more help.

这篇关于更改栏按钮的称号的UIImagePickerController的导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆