Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 728
pawelropa Avatar asked Jun 20 '12 13:06

pawelropa


2 Answers

The secret is setting ALL THREE of these properties on the NSTextField...

myTextField.bezeled         = NO; myTextField.editable        = NO; myTextField.drawsBackground = NO; 
like image 115
Alex Gray Avatar answered Sep 23 '22 15:09

Alex Gray


There is a property in the .xib file, on the interface builder window for the text field, under attribute inspector

  1. Check the Display Draws Background
  2. Select a background color. Select clear color for transparent background.

enter image description here

like image 25
Gamma-Point Avatar answered Sep 25 '22 15:09

Gamma-Point