Friday, March 8, 2024
HomeiOS Developmentios - The best way to correctly obtain toolbar transparency and blurry...

ios – The best way to correctly obtain toolbar transparency and blurry with out system coloration change


Right here for instance, that is from the native messaging app on iOS the footer backside bar is black because the background. It would not have any totally different coloration, lighter than that:

enter image description here

Right here it’s properly clear and blurry when the message scrolls move behind it:
enter image description here

I need to obtain this impact in my code, nonetheless I am unable to obtain this in any respect.
Right here is an instance of my app, when content material is empty:
enter image description here

And right here is with content material behind it:
enter image description here

I see another apps are utilizing similar approach, just like the fb messenger or sign apps.

Right here is my code:

let toolbarBackground = UIToolbarAppearance()
toolbarBackground.backgroundEffect = UIBlurEffect(model: .systemUltraThinMaterial)

toolbarBackground.backgroundColor = UIColor(dynamicProvider: { traitCollection in
    return traitCollection.userInterfaceStyle == .darkish ? 
        UIColor.black.withAlphaComponent(0.5) : UIColor.white.withAlphaComponent(0.8)
})

toolbarBackground.shadowColor = .clear
UIToolbar.look().standardAppearance = toolbarBackground
UIToolbar.look().scrollEdgeAppearance = toolbarBackground

The half UIColor.white.withAlphaComponent(0.8) is for mild mode, and has no impact on darkish mode.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments