美文网首页Swift之家
Swift 修改TabBar、NavigationBar分割线颜

Swift 修改TabBar、NavigationBar分割线颜

作者: 小小土豆dev | 来源:发表于2018-10-09 23:07 被阅读29次

    有时候系统自带的 TabBar 或 NavigationBar 分割线颜色和我们App里设计的不一致,此时就需要自定义系统的分割线颜色。

    修改 TabBar 分割线颜色

    tabBar.backgroundImage = UIImage()

    tabBar.shadowImage = tabBarShadowImage()

    func tabBarShadowImage() -> UIImage? {

      UIGraphicsBeginImageContextWithOptions(CGSize(width: UIScreen.width(), height: 0.5), false, 0)

      let path = UIBezierPath.init(rect: CGRect.init(x: 0, y: 0, width: UIScreen.width(), height: 0.5))

      UIColor.red.setFill()// 自定义TabBar分割线颜色

      path.fill()

      let image = UIGraphicsGetImageFromCurrentImageContext()

      UIGraphicsEndImageContext()

      return image

    }

    修改 NavigationBar 分割线颜色

    navigationBar.setBackgroundImage(UIImage(), for: .default)

    navigationBar.shadowImage = navBarShadowImage()

    func navBarShadowImage() -> UIImage? {

      UIGraphicsBeginImageContextWithOptions(CGSize(width: UIScreen.width(), height: 0.5), false, 0)

      let path = UIBezierPath.init(rect: CGRect.init(x: 0, y: 0, width: UIScreen.width(), height: 0.5))

      UIColor.blue.setFill()// 自定义NavigationBar分割线颜色

      path.fill()

      let image = UIGraphicsGetImageFromCurrentImageContext()

      UIGraphicsEndImageContext()

      return image

    }

    相关文章

      网友评论

        本文标题:Swift 修改TabBar、NavigationBar分割线颜

        本文链接:https://www.haomeiwen.com/subject/dptjaftx.html