NSTextField transparent background
As of 10.12 you can just do:
let label = NSTextField(labelWithString: "HELLO")
The secret is setting ALL THREE of these properties on the NSTextField
...
myTextField.bezeled = NO;
myTextField.editable = NO;
myTextField.drawsBackground = NO;
Came here looking for this too, and have got the background to give me a transparent grey. Key is to not have a bezel. My code below:
NSTextField *yourLabel = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, width , height * 1.0/3.0)];
yourLabel.editable = false;
yourLabel.bezeled = false;
[yourLabel setTextColor:[NSColor blackColor]];
[yourLabel setBackgroundColor:[NSColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.1]];
For completeness I had got the width and height earlier because they get used many times for layout:
height = self.window.frame.size.height;
width = self.window.frame.size.width;
There is a property in the .xib file, on the interface builder window for the text field, under attribute inspector
- Check the Display Draws Background
- Select a background color. Select clear color for transparent background.