的UIImagePickerController导航栏项目的变动情况(Change case of

2019-11-03 12:45发布

免责声明 :我知道这可能不是苹果的批准,我意识到遍历视图层次是编程不安全。 我想弄清楚我自己的好奇心:)

我想改变的UIImagePickerController的导航栏项目的情况。

该方法适用于标题文本:

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

但是,这并不对取消按钮的工作(显然它不是一个取消按钮正确的位置,但在视图层次,我不能找到它)。

如何更改过的取消按钮?

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

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


文章来源: Change case of UIImagePickerController navigation bar items