iOS 15 Navigation bar color change dynamically - ios

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

Related

Swift tabBar not displaying correctly

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

How to change UIBarButtonItem tint color based on whether UINavigationBar is showing large or normal (collapesed)?

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?

How can I set UITabBarAppearance() without overriding UITabBarItem.appearance()?

I style my UITabBarItem titles globally as follows:
UITabBarItem.appearance().setTitleTextAttributes(TextStyle.tabTitle(colored: false).attributes, for: .normal)
UITabBarItem.appearance().setTitleTextAttributes(TextStyle.tabTitle(colored: true).attributes, for: .selected)
In iOS 15, I need to override the new behaviour where the tab bar background is hidden at the scroll edges. I can do that like this:
let appearance = UITabBarAppearance()
appearance.configureWithDefaultBackground()
tabBar.standardAppearance = appearance
tabBar.scrollEdgeAppearance = appearance
However, this seems to override the font of the tab bar item titles, and reset them back to the default. I can't seem to override the tab bar hiding behaviour, and retain my custom font.
You can use
let tabBarItemAppearance = UITabBarItemAppearance()
tabBarItemAppearance.normal.titleTextAttributes = [TextStyle.tabTitle(colored: false).attributes]
tabBarItemAppearance.selected.titleTextAttributes = [TextStyle.tabTitle(colored: false).attributes]

NavigationBar Logo blurred in iOS 13 devices

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?

Why UIPageController on clear color returns black?

I want to change my UIPageController background color and do the next:
let appearance = UIPageControl.appearance()
appearance.backgroundColor = UIColor.clearColor()
but it returns me black color. How can I make it transparent?

Resources