【问题标题】:Set BackgroundColor of Second View and Supplementary View of UISplitViewController设置 UISplitViewController 的 Second View 和 Supplementary View 的 BackgroundColor
【发布时间】:2021-12-06 13:24:54
【问题描述】:

如您所见,在一个 3 行的 SplitViewController 中,在顶部,有与背景颜色不匹配的 while 空间。

有什么方法可以将它们设置为与蓝色背景相同?

红色背景颜色由 self.navigationController?.navigationBar.backgroundColor = .red 设置。但是那里设置的颜色和背景颜色不匹配。

【问题讨论】:

    标签: background-color uisplitviewcontroller


    【解决方案1】:

    最后我必须从颜色创建一个图像并将图像设置为背景。

    感谢这篇文章。

    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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 2016-07-24
      • 2011-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多