到目前为止我处理梯度导航栏下面的manner_处理导航栏背景渐变
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
但现在在iPhone XI有问题,由于“64”作为导航栏高度梯度below_
请建议本可以在每种情况下可以使用动态修复。
那么,这是一个很好的实现方式,但现在我只是检查了 static let IS_IPHONE_X = UIDevice.current.userInterfaceIdiom == .phone && max(UIScreen.main.bounds.size.width,UIScreen.main.bounds .size.height)== 812.0 如果DeviceType.IS_IPHONE_X { defaultNavigationBarFrame =的CGRect(X:0,Y:0,宽度:sizeLength,高度:88) } 否则{ defaultNavigationBarFrame =的CGRect(X:0, y:0,width:sizeLength,height:64) } –