简体   繁体   中英

How to customize appearance of UIPrintInteractionController

The apple blue does not match my app colors so the print dialog is very jarring.

In my iPhone app I am able to get the proper nav bar and background colors with the following UIPrintInteractionControllerDelegate code.

- (UIViewController *)printInteractionControllerParentViewController:   (UIPrintInteractionController *)printInteractionController
{
   return self.navigationController;
}
- (void)printInteractionControllerDidPresentPrinterOptions:(UIPrintInteractionController *)printInteractionController
{
   self.navigationController.topViewController.view.backgroundColor = [UIColor whiteColor];   
}

The problem is that I use a custom UIPrintPageRenderer class to render my page. This seems to trigger a screen that pops up after the print job has been sent. It has a nav bar with a Done button and a message below saying "sending to printer". I assume this is so you can see multiple pages being sent (I only have one). This pops up after the options dialog has gone away and you have been returned to your original screen where you initiated everything.

The "sending to printer" screen is blue and ugly to the max. Is there anyway to eliminate it or customize its appearance?"

I don't know your full code, but you could try the appearance protocol. That essentially allows you to set the universal colour (or other property) of particular UI elements like buttons and bars. So you could, to set the background colour of the print controller's nav bar, use the following code:

[[UINavigationBar appearance] setTintColor:[UIColor redColor]];

That would make all navigation bars in your app, including the print navigation controller's, to be red. You can then later change ones that you do not want to be red by setting their bar's appearance (ie self.navigationController.navigationBar.tintColor).

By the way, this works for iOS 7 , iOS 6 does not have the tint colour property, I think it instead just uses background colour.

for iOS 13.0 + you can use this that's worked for me

if #available(iOS 13.0, *) {
        let appearance = UINavigationBarAppearance()
        appearance.configureWithOpaqueBackground()
        appearance.backgroundColor = UIColor.orange
        appearance.titleTextAttributes = [.foregroundColor: UIColor.white] // With a red background, make the title more readable.
        UINavigationBar.appearance().standardAppearance = appearance
        UINavigationBar.appearance().scrollEdgeAppearance = appearance
        UINavigationBar.appearance().compactAppearance = appearance // For iPhone small navigation bar in landscape.
} else {
        UINavigationBar.appearance().tintColor = UIColor.white
        UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.white]
        UINavigationBar.appearance().barTintColor = UIColor.orange
}
    UIBarButtonItem.appearance().tintColor = UIColor.white
    UISegmentedControl.appearance().tintColor = UIColor.orange

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM