Prevent UINavigationBar in Share Extension from inheriting main application appearance settings

Viewed 664

I created a share extension for my for which I had to create my own UI in the Storyboard. The entire thing works great except for the fact that the navigation bar inherits the main app's appearance. As examples:

Here it is in the NYT app: enter image description here

Here it is in the Vice app: enter image description here

How can I set my own appearance?

4 Answers

I found a way!

Just draw an Image with your color!

func getTopWithColor(color: UIColor, size: CGSize) -> UIImage {
    let rect = CGRect(x: 0,y:  0,width: size.width,height: size.height)
    UIGraphicsBeginImageContextWithOptions(size, false, 0)
    color.setFill()
    UIRectFill(rect)
    //if let img = UIImage(named: "test.jpg") {
        //img.draw(in: CGRect(x: 0,y: 0,width: size.width,height: size.height))
    //    img.draw(in: CGRect(x: 0,y: 0,width: size.width,height: size.height), blendMode: .darken, alpha: 0.5)
    //}
    let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!

    UIGraphicsEndImageContext()
    return image
}

.

override func viewDidLoad() {

let c = UIColor(red: 0.5765, green: 0.2784, blue: 0, alpha: 0.5)
    //c.withAlphaComponent(CGFloat(0))
    self.navigationController?.navigationBar.tintColor = UIColor.black
    let navSize = self.navigationController?.navigationBar.frame.size
    let image1 = getTopWithColor(color: c, size: navSize!)

    self.navigationController?.navigationBar.setBackgroundImage(image1, for: .default)
Related