I want to use NSVisualEffectView
with dark vibrancy, but I find the effect too pale in some situations, so I'd like to darken the background.
Here is an example app, using NSBox
views to provide a darker background.
We can see that the NSBox
'primary' appearance manages to overlay the background and the button happily sits on top of that. However, on the NSBox
with custom appearance, the button appears to 'cut' through the background to the visual effect view beneath.
I've tried subclassing NSVisualEffectView
and overriding -drawRect:
to fill it with a different color and the result is the same.
Is there a way to overlay vibrant controls over other views?
Learn how to create an overlay effect: Overlay Click anywhere to turn off the overlay effect Turn on the overlay effect How To Create an Overlay Effect Step 1) Add HTML: Use any element and place it anywhere inside the document: Example <div id="overlay"></div> Step 2) Add CSS: Style the overlay element: Example #overlay {
Turns out, CSS has several ways of layering "meta-content" on top of a background image. Another way to achieve the same is by using the box-shadow property with a huge spread value and the inset setting. Here's a CodePen with this implementation as well:
Now, scroll down the same tab. Center the background image and activate the Multiply option in the Background image blend drop-down menu. You have a lot of other options as well that can help you reach the exact result you want. And, there you have the final result: The second example we’re going to show you how to create is the blurb section.
An example could be a hero section, or the above-the-fold content on basically any marketing site these days. Some times, we need to improve the contrast between the text and the background image.
The Visual Effect View seems to have two important layers: Backdrop and Tint. Setting both of these to the "right" black seems to do the trick, but you'll need to do this anytime the bounds change.
for (CALayer *sublayer in self.vibrancyView.layer.sublayers) {
if ([sublayer.name isEqualToString:@"Backdrop"]) {
NSLog(@"Backdrop: %@", sublayer.backgroundColor);
sublayer.backgroundColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:0.45].CGColor;
} else if ([sublayer.name isEqualToString:@"Tint"]) {
NSLog(@"Tint: %@", sublayer.backgroundColor);
sublayer.backgroundColor = [NSColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With