0

如何在NSTextField 我添加了一个NSVisualEffectView带有界面构建器并尝试使用NSAppearance为标签添加活力的情况下实现活力效果

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

在此处输入图像描述

4

1 回答 1

0
  1. 覆盖allowsVibrancy

Objective-C

@interface VibrancyTextField : NSTextField
@end

@implementation VibrancyTextField

- (BOOL)allowsVibrancy {
    return YES;
}

@end

迅速

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

  1. 使用 textColor 作为标准颜色。RGB 或默认标签颜色等其他颜色将不起作用。

Objective-C

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

迅速

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

截屏

于 2022-01-18T18:58:26.230 回答