1

As you can see, in a 3 lines SplitViewController, on the top, there are while space that are not match the background color.

Any way to set them the same as the blue background?

enter image description here

enter image description here

The red background color was set by self.navigationController?.navigationBar.backgroundColor = .red. But set color there can't match the background color.

Owen Zhao
  • 3,205
  • 1
  • 26
  • 43

1 Answers1

0

At last I have to create an image from color and set the image as background.

Thanks to this post.

Creating a UIImage from a UIColor to use as a background image for UIButton

extension UIImage {
    static func from(color: UIColor) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContext(rect.size)
        let context = UIGraphicsGetCurrentContext()
        context!.setFillColor(color.cgColor)
        context!.fill(rect)
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img!
    }
}
if let nav = self.navigationController {
    nav.navigationBar.setBackgroundImage(UIImage.from(color: UIColor(named: "Blue")!), for: .default)
}
Owen Zhao
  • 3,205
  • 1
  • 26
  • 43