更改UIImagePickerController导航栏项的大小写

时间:2014-12-03 21:59:27

标签: ios objective-c uiimagepickercontroller

免责声明:我意识到这可能不会被Apple批准,我意识到遍历视图层次结构在程序上是不安全的。我试图弄清楚自己的好奇心:)

我想更改UIImagePickerController导航栏项的大小写。

这适用于标题文字:

viewController.navigationItem.title = [viewController.navigationItem.title uppercaseString];

但这对取消按钮不起作用(显然它不是取消按钮的正确位置,但我无法在视图层次结构中找到它)。

如何更改取消按钮?

[viewController.navigationItem.rightBarButtonItems enumerateObjectsUsingBlock:^(UIBarButtonItem* btn, NSUInteger idx, BOOL *stop) {
    btn.title  = [btn.title lowercaseString];
}];

1 个答案:

答案 0 :(得分:1)

我不知道如何访问现有的取消按钮,但您可以将其替换为:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{    
    // add done button to right side of nav bar
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"cancel"
                                                                     style:UIBarButtonItemStylePlain
                                                                    target:self
                                                                    action:@selector(done:)];

    UINavigationBar *bar = navigationController.navigationBar;
    UINavigationItem *topItem;

    topItem = bar.topItem;
    topItem.rightBarButtonItem = cancelButton;
}

修改

我认为这会做你想做的事情:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    for (UIView *view in navigationController.navigationBar.subviews)
    {
        if ([view isKindOfClass:[UIButton class]])
        {
            UIButton *btn = (UIButton *)view;
            [btn setTitle:[btn.titleLabel.text lowercaseString] forState:UIControlStateNormal];
        }
    }
}