Search code examples
macoscocoanstextfield

NSTextField transparent background


I create transparent NSTextField

self.myTextField = [[NSTextField alloc] initWithFrame:CGRectMake(backgroundView.frame.origin.x + backgroundView.frame.size.width + 20, self.projectTitle.frame.origin.y - 30.0, 100, 20)];
self.myTextField.editable = NO;
self.myTextField.bezeled = NO;
self.myTextField.drawsBackground = YES;
self.myTextField.backgroundColor = [NSColor clearColor];
self.myTextField.selectable = NO;
self.myTextField.font = [NSFont fontWithName:@"Helvetica Neue" size:16];

    [self addSubview:self.compressingTime];

And as a result text look bad. enter image description here If I set background color

    self.myTextField.backgroundColor = [NSColor colorWithCalibratedRed:0.85 green:0.85 blue:0.85 alpha:1.0];

everything looks okenter image description here I have also tried with drawsBackground = NO; Do you guys know how to fix this?


Solution

  • I ended up using CATextLayer instead NSTextField.