VariableBlur icon indicating copy to clipboard operation
VariableBlur copied to clipboard

Is there a way to create a darker blur?

Open Pranoy1c opened this issue 1 year ago • 3 comments

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?

Pranoy1c avatar Aug 15 '24 21:08 Pranoy1c

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:

https://github.com/nikstar/VariableBlur/blob/41698eecb3373550b2100dbcd308d886501d7033/Sources/VariableBlur/VariableBlur.swift#L69-L72

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

Also change style used to explicitly dark material:

https://github.com/nikstar/VariableBlur/blob/41698eecb3373550b2100dbcd308d886501d7033/Sources/VariableBlur/VariableBlur.swift#L42

Any PRs that tackle this will be absolutely welcome!

nikstar avatar Aug 16 '24 09:08 nikstar

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

Pranoy1c avatar Aug 17 '24 18:08 Pranoy1c

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.

nikstar avatar Aug 18 '24 13:08 nikstar