Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the navigation bar color when user taps "More"on UIActivityViewController?

Whenever the user wants to select a new share method or action that isn't listed by default, by tapping the "More" button on the UIActivityViewController generated share sheet, a new view is displayed, something like this:

Followup view

As you can see, the navigation bar itens are white, while it's background is a light grey. How can I change these colors to reflect my app UI?

like image 358
Bruno Machado - vargero Avatar asked Jan 09 '15 20:01

Bruno Machado - vargero


People also ask

How do I customize my navigation bar?

From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen. Note: This option will also affect the location you swipe when using Swipe gestures.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.

Can you change the navigation bar on iPhone?

Change the Bar StyleA user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


1 Answers

I did this and it works for me:

Sublclass UIActivityViewController and override -(void)presentViewController:animated:completion:

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
[viewControllerToPresent.view setTintColor:[[UINavigationBar appearance] tintColor]];
for (UIView *view in viewControllerToPresent.view.subviews) {
    if ([view isKindOfClass:[UINavigationBar class]]) {
        UINavigationBar *navigationBar = (UINavigationBar*)view;
        UIImage *navigationBarImage = [[UINavigationBar appearance] backgroundImageForBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
        [navigationBar setBackgroundImage:navigationBarImage forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
        [navigationBar setTitleTextAttributes:[[UINavigationBar appearance] titleTextAttributes]];
    }
}

[super presentViewController:viewControllerToPresent animated:flag completion:^{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    if (completion) {
        completion();
    }
}];
}
like image 176
Serluca Avatar answered Nov 14 '22 21:11

Serluca