Implement vibrancy effect on NSTextField

197 Views Asked by At

How can I implement vibrancy effect on NSTextField I added an NSVisualEffectView with interface builder and try to use NSAppearance to add vibrancy to the label

var varLabel = NSTextField()
varLabel.stringValue = "Some"
varLabel.appearance = NSAppearance(named: .vibrantLight)

enter image description here

1

There are 1 best solutions below

0
On
  1. Override allowsVibrancy.

Objective-C

@interface VibrancyTextField : NSTextField
@end

@implementation VibrancyTextField

- (BOOL)allowsVibrancy {
    return YES;
}

@end

Swift

class VibrancyTextField: NSTextField {
    override var allowsVibrancy {
        return true
    }
}

  1. Use textColor as Standard Colors. Other colors like RGB or Default Label Color won't work.

Objective-C

VibrancyTextField *testField = [VibrancyTextField new];
testField.stringValue = @"Hello ████████████████████";
testField.textColor = NSColor.systemGrayColor;
[testField release];

Swift

let testField = VibrancyTextField()
testField.stringValue = "Hello ████████████████████"
testField.textColor = .systemGrayColor

Screenshot