I have an app logo in the Navigation bar title view. It was showing fine before. But when I'm using the app in iOS 13 devices (iPhone 11, iPhone X), the app logo is blurry. Image size is 225*75
Here is the sample image,
I'm using navigationItem titleView:
self.navigationItem.titleView = UIImageView(image: UIImage(named: "logo"))
Also, tried navigationBarAppearance as well.
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.backgroundColor = CustomColor.COLOR_PRIMARY
//appearance.titleTextAttributes = [.foregroundColor: CustomColor.COLOR_ACCENT]
let bar = self.navigationController?.navigationBar
bar?.scrollEdgeAppearance = appearance
bar?.standardAppearance = appearance
bar?.compactAppearance = appearance
}
But it's not working. Can you help me to fix that?
Related
I'm trying to change the navigationbar color dynamically. But the problem is that unless I scroll to the top only the the new color is visible otherwise the old color is seen. I'm using the below code to set the color. My requirement is that if I change the color I want the navigation bar to show the new color irrespective of the scrolling. I would really appreciate your suggestions.
let navigationBarAppearance = UINavigationBarAppearance()
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().compactAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
navigationBarAppearance.backgroundColor = .purple
I've tried the code thats been specifically given for iOS 15 and later
In Xcode I have this app that uses tabBarItem. There are 5 items and occasionally when I'm on a specific page I get this weird overlay of the tabBarItems (see pictures). I say occasionally, because it does not do it always but it is still very frequent. Not sure if it is just a limitation with tabBarItem or if I have a bug.
This is how it SHOULD look:
This is how it SHOULD NOT look, but does:
As you can see in the second image the tabBar is being overlayed onto the other text rather than disappearing behind it. It's odd that it behaves differently for each tab.
I can fix the issue with
if #available(iOS 15.0, *) {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .black
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = UITabBar.appearance().standardAppearance
}
But need a fix that would work for IOS 11+
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().backgroundColor = .black
Is it possible to change large navigation bar height?
self.navigationItem.largeTitleDisplayMode = .always
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.addSubview(expandedNavBar)
I dont think you can change navigationBar height because of Apple HIG. If you want to change navigationBar height , you can remove navigationBar and you can show your own customview to user like navigationBar
If you want to make the navigationBar a little bigger, you can try this trick by adding an empty string to the prompt property.
self.navigationItem.prompt = ""
Ok, I found this way:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 200
let attributes: [NSAttributedString.Key: Any] = [ .paragraphStyle: paragraphStyle]
let navigationBar = navigationController?.navigationBar
if #available(iOS 13, *) {
if let appearance = navigationBar?.standardAppearance {
appearance.largeTitleTextAttributes = attributes
navigationBar?.standardAppearance = appearance
navigationBar?.scrollEdgeAppearance = appearance
}
} else {
navigationBar?.largeTitleTextAttributes = attributes
}
Setting the appearance of a UINavigationBar title, background, etc. based on whether it is showing large or normal is no problem. But how to update the appearance / tint color of the bar button items accordingly?
Have a code at the following appearance and the code that I used to create it:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [MyCiewController.self]).tintColor = .orange
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = .orange.withAlphaComponent(0.5)
appearance.backgroundEffect = UIBlurEffect(style: .systemChromeMaterialDark)
// Set different title colors for large and normal mode
appearance.titleTextAttributes = [.foregroundColor: .white]
appearance.largeTitleTextAttributes = [.foregroundColor: .black]
// No effect
appearance.buttonAppearance.normal.titleTextAttributes = [.foregroundColor: .white]
UINavigationBar.appearance(whenContainedInInstancesOf: [MyCiewController.self]).standardAppearance = appearance
So, setting different colors for large and normal title is no problem. However, I did not find any appearance property to do the same for the bar button items. My best guess was to use buttonAppearance but this had no effect.
How to make the "Done" button white in the normal nav bar? Is it possible to use appearances to solve this?
I am trying to add a background image to my nav bar using the UINavigationBarAppearance. However, the imageView size is bigger than the navigation bar content view.. How do I fix this?
Result: Notice the imageview overlaps with the safearea
Heiarchy debugger
Code:
private func setupNavBar() {
navigationItem.largeTitleDisplayMode = .never
guard let navigationController = navigationController else { return }
let appearance = navigationController.navigationBar.standardAppearance.copy()
appearance.configureWithTransparentBackground()
appearance.backgroundImage = UIImage.checkmark
appearance.backgroundImageContentMode = .scaleAspectFit
appearance.backgroundColor = .red
navigationController.navigationBar.standardAppearance = appearance
}
Found an alternative. Instead of using the appearance background image, I set the titleView on the navigation item.
let imageView = UIImageView(image: UIImage.checkmark)
imageView.contentMode = .scaleAspectFit
navigationItem.titleView = imageView