IOS 15 自定義導航欄圖片顯示問題的解決
導航欄為圖片的時候,進入是白色的,需要往上滑一點才能出現
OC
UIImage *bgImage = [[UIImage imageNamed:@"nav_other"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
[barApp setBackgroundImage:bgImage];
self.navigationController.navigationBar.scrollEdgeAppearance = barApp;
self.navigationController.navigationBar.standardAppearance = barApp;
} else {
// Fallback on earlier versions
}
swift
if #available(iOS 13.0, *) {
let barApp = UINavigationBarAppearance.init()
barApp.backgroundImage = bgImg
self.navigationController?.navigationBar.scrollEdgeAppearance = barApp
self.navigationController?.navigationBar.standardAppearance = barApp
barApp.titleTextAttributes = [NSAttributedString.Key.font: UIFont.italicSystemFont(ofSize: 16),NSAttributedString.Key.foregroundColor: UIColor.white]
barApp.titleTextAttributes =
[NSAttributedString.Key.foregroundColor: UIColor.white]
}