Piy*_*hur 5 ios swift iphone-x
到目前为止,我通过以下方式处理导航栏中的渐变_
let gradient = CAGradientLayer()
let sizeLength = UIScreen.main.bounds.size.height * 2
let defaultNavigationBarFrame = CGRect(x: 0, y: 0, width: sizeLength, height: 64)
gradient.frame = defaultNavigationBarFrame
gradient.colors = [UIColor(hex:"92CF1F").cgColor, UIColor(hex:"79AB1B").cgColor]
UINavigationBar.appearance().setBackgroundImage(self.image(fromLayer: gradient), for: .default)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().clipsToBounds = false
if DeviceType.IS_IPAD{
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : UIFont .systemFont(ofSize: 24, weight: UIFontWeightLight), NSForegroundColorAttributeName: UIColor.white]
}
else
{
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : UIFont .systemFont(ofSize: 20, weight: UIFontWeightLight), NSForegroundColorAttributeName: UIColor.white]
}
UISearchBar.appearance().backgroundColor = UIColor.clear
Run Code Online (Sandbox Code Playgroud)
但是现在在iPhone XI中有问题,因为"64"作为渐变的导航栏高度如下
请建议一个可以在每种情况下动态使用的修复程序.
您不仅不能再假定导航栏高度为 64,而且不能再假定静态高度。
我认为实现您想要做的事情的最简单方法是将UINavigationController'sinit(navigationBarClass:toolbarClass:)方法与自定义UINavigationBar子类一起使用,该子类重写layerClass以直接指定您的方法CAGradientLayer。
不幸的是,我不认为有一种方法可以“解雇并忘记”这一点UIAppearance。
| 归档时间: |
|
| 查看次数: |
1207 次 |
| 最近记录: |