Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

ios - Change case of UIImagePickerController navigation bar items

Disclaimer: I realize this may not be approved by Apple, and I realize traversing the view hierarchy is programmatically unsafe. I'm trying to figure it out for my own curiosity :)

I'd like to change the case of a UIImagePickerController's navigation bar items.

This works for the title text:

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

But this doesn't work for the cancel button (clearly it's not the right location for the cancel button, but I can't find it in the view hierarchy).

How can I change the cancel button too?

[viewController.navigationItem.rightBarButtonItems enumerateObjectsUsingBlock:^(UIBarButtonItem* btn, NSUInteger idx, BOOL *stop) {
    btn.title  = [btn.title lowercaseString];
}];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I don't know how to access the existing cancel button, but you can replace it doing something like this:

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

EDIT:

This will do what you want, I think:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...