Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to create a darker blur? #5

Open
Pranoy1c opened this issue Aug 15, 2024 · 3 comments
Open

Is there a way to create a darker blur? #5

Pranoy1c opened this issue Aug 15, 2024 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Pranoy1c
Copy link

Is there a way to create a darker blur? Dark enough so that the status bar always shows white text instead of black? How can I control?

@nikstar
Copy link
Owner

nikstar commented Aug 16, 2024

Currently, no. As a workaround overlay Color.black.opacity(...) to Color.clear gradient.

In fact I disable darkening and saturation layers of UIVisualEffectView because it creates a visible line at clear end of the view:

// Get rid of the visual effect view's dimming/tint view, so we don't see a hard line.
for subview in subviews.dropFirst() {
subview.alpha = 0
}

Ideally, we wouldn't do this and instead apply opacity gradient.

Also change style used to explicitly dark material:

super.init(effect: UIBlurEffect(style: .regular))

Any PRs that tackle this will be absolutely welcome!

@nikstar nikstar added enhancement New feature or request good first issue Good for newcomers labels Aug 16, 2024
@Pranoy1c
Copy link
Author

I was able to create darkened gradient blur using the solution by @Sweeper here:

https://stackoverflow.com/a/78877606/1634905

In the VariableBlurUIView, add:

let darkLayer = CALayer()

Then, in the init, add:

darkLayer.contents = gradientImage
darkLayer.zPosition = -1
backdropLayer?.superLayer?.addSublayer(darkLayer)

Add the following functions:

open override func layoutSublayers(of layer: CALayer) {
    darkLayer.frame = subviews.first?.layer.frame ?? .zero
}

And change the color0 in makeGradientImage func to black with alpha which you think is appropriate:

CIColor(color: UIColor.black.withAlphaComponent(0.7))

Result:

Screenshot 2024-08-17 at 2 29 08 PM

@nikstar
Copy link
Owner

nikstar commented Aug 18, 2024

Oh, you use makeGradientImage. Nice. Note that variableBlur uses opacity to determine blur radius so if you reuse the same clear to 0.7 black gradient, variable blur will only go from 0 to 0.7*maxBlurRadius.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants