到目前爲止我處理梯度導航欄下面的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) } –