Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overlay a background color over an NSVisualEffectView and use vibrant controls?

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.

enter image description here

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?

like image 863
joerick Avatar asked Oct 23 '14 11:10

joerick


People also ask

How to create an overlay effect?

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 {

How to layering Meta Content on top of a background image?

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:

How to create a blurb using a background image?

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.

What is an example of contrast in content design?

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.


1 Answers

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;
    }
}
like image 132
Dimitri Bouniol Avatar answered Oct 17 '22 10:10

Dimitri Bouniol