Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var colorTint: UIColor // tint color. default is nil
var colorTintAlpha: CGFloat // tint color alpha. default is 0
var blurRadius: CGFloat // blur radius. default is 0
var scale: CGFloat // scale factor. default is 1
var saturation: CGFloat // saturation factor. default is 1
```

If you want `colorTintAlpha` to be different from `0`, make sure you always set it right after setting the `colorTint` or it may not be applied as expected.
Expand Down
17 changes: 15 additions & 2 deletions Sources/VisualEffectView/VisualEffectView+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public struct VisualEffect: UIViewRepresentable {
*/
let blurRadius: CGFloat

/**
The saturation factor.

Values above 1.0 increase saturation, values below 1.0 decrease saturation, and 1.0 maintains original saturation.

The default value is `1.0`.
*/
let saturation: CGFloat

/**
The scale factor for the blur effect.

Expand All @@ -51,12 +60,14 @@ public struct VisualEffect: UIViewRepresentable {
- colorTint: The tint color to apply to the blur effect. Defaults to `nil`.
- colorTintAlpha: The alpha component of the tint color. Defaults to `0.0`.
- blurRadius: The radius of the blur effect. Defaults to `0.0`.
- saturation: The saturation adjustment factor. Values above 1.0 increase saturation, values below 1.0 decrease saturation. Defaults to `1.0`.
- scale: The scale factor for the blur effect. Defaults to `1.0`.
*/
public init(colorTint: Color? = nil, colorTintAlpha: CGFloat = 0, blurRadius: CGFloat = 0, scale: CGFloat = 1) {
public init(colorTint: Color? = nil, colorTintAlpha: CGFloat = 0, blurRadius: CGFloat = 0, saturation: CGFloat = 1, scale: CGFloat = 1) {
self.colorTint = colorTint
self.colorTintAlpha = colorTintAlpha
self.blurRadius = blurRadius
self.saturation = saturation
self.scale = scale
}

Expand All @@ -69,6 +80,7 @@ public struct VisualEffect: UIViewRepresentable {
}
view.colorTintAlpha = colorTintAlpha
view.blurRadius = blurRadius
view.saturation = saturation
view.scale = scale

return view
Expand All @@ -80,6 +92,7 @@ public struct VisualEffect: UIViewRepresentable {
}
uiView.colorTintAlpha = colorTintAlpha
uiView.blurRadius = blurRadius
uiView.saturation = saturation
uiView.scale = scale
}
}
Expand All @@ -90,7 +103,7 @@ public struct VisualEffect: UIViewRepresentable {
.frame(width: 400, height: 400)
Color.red
.frame(width: 200, height: 100)
VisualEffect(colorTint: .white, colorTintAlpha: 0.5, blurRadius: 18)
VisualEffect(colorTint: .white, colorTintAlpha: 0.5, blurRadius: 18, saturation: 2.0)
.frame(width: 300, height: 200)
}
}
Expand Down
14 changes: 13 additions & 1 deletion Sources/VisualEffectView/VisualEffectView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ open class VisualEffectView: UIVisualEffectView {
}
}

/**
Saturation factor.

Values above 1.0 increase saturation, values below 1.0 decrease saturation, and 1.0 maintains original saturation.

The default value is 1.0.
*/
open var saturation: CGFloat {
get { return _value(forKey: .saturationDeltaFactor) ?? 1.0 }
set { _setValue(newValue, forKey: .saturationDeltaFactor) }
}

/**
Scale factor.

Expand Down Expand Up @@ -103,7 +115,7 @@ private extension VisualEffectView {
}

enum Key: String {
case colorTint, colorTintAlpha, blurRadius, scale
case colorTint, colorTintAlpha, blurRadius, saturationDeltaFactor, scale
}

}
Expand Down
Loading