Transparent NSTextField

  • Hi everybody,

    I’m trying to add a transparent editable NSTextField to a view. As long as the field is not editable (e.g. a label), everything is fine; but with an editable field, I get a background fill. I imagine this is under the window NSTextView responsibility. Has someone already succeeded in programming a totally transparent NSTextField, or shall I recourse to a CATextLayer instead?

    Thanks,
    Vincent
  • On 28 Jun 2012, at 10:22 AM, Vincent Habchi wrote:

    > I’m trying to add a transparent editable NSTextField to a view. As long as the field is not editable (e.g. a label), everything is fine; but with an editable field, I get a background fill. I imagine this is under the window NSTextView responsibility. Has someone already succeeded in programming a totally transparent NSTextField, or shall I recourse to a CATextLayer instead?

    My next step (which is my way of saying I haven't tried it) would be to investigate -[<NSWindowDelegate> windowWillReturnFieldEditor:toObject:], and set the field editor's backgroundColor (it's in NSText) to the transparent color.

    — F
  • > My next step (which is my way of saying I haven't tried it) would be to investigate -[<NSWindowDelegate> windowWillReturnFieldEditor:toObject:], and set the field editor's backgroundColor (it's in NSText) to the transparent color.

    I'll do that, yes. Besides, I need to override the cursor to make it look like an underscore _ (the whole point is to make the input field look like a vintage console editing field).

    I guess I'll not escape writing a custom NSTextView to serve as the window field editor.

    Thanks for the hint!
    Vincent
  • In IB you can set the "Draws Background" property to no (uncheck the box) or send the NSTextField a SetDrawsBackground: NO message.

    On Jun 28, 2012, at 11:22 AM, Vincent Habchi wrote:

    > Hi everybody,
    >
    > I’m trying to add a transparent editable NSTextField to a view. As long as the field is not editable (e.g. a label), everything is fine; but with an editable field, I get a background fill. I imagine this is under the window NSTextView responsibility. Has someone already succeeded in programming a totally transparent NSTextField, or shall I recourse to a CATextLayer instead?
    >
    > Thanks,
    > Vincent

    Charlie Dickman
    <3tothe4th...>
  • Le 28 juin 2012 à 18:30, Charlie Dickman <3tothe4th...> a écrit :

    > In IB you can set the "Draws Background" property to no (uncheck the box) or send the NSTextField a SetDrawsBackground: NO message.

    Yep, but that’s working only for non-editable fields. In an editable field, I get a background – but I suspect this is caused by highlighting. So I will try to override the standard highlighting behavior to get just some text coloring while letting the background clear.

    Vincent
  • Hi Vincent,

    Have you tried setDrawsBackground:NO on your NSTextField?

    Below was what I used.

    I don't know if any of the other instance variables I set are important for your case but they might be.

    HTH,
    Joel

    - (void) initTextField;
    {
      [self setBordered:NO];
      [self setFocusRingType:NSFocusRingTypeNone];
      [self setBezelStyle:NSTextFieldSquareBezel];
      [self setBezeled:NO];
      [self setEnabled:YES];
      [self setSelectable:YES];
      [self setEditable:YES];
      [self setAlignment:NSNaturalTextAlignment];
      [self setBackgroundColor:[NSColor whiteColor]];
      [self setDrawsBackground:NO];
    }

    This was the original message:

    Hi everybody,

    I’m trying to add a transparent editable NSTextField to a view. As long as the field is not editable (e.g. a label), everything is fine; but with an editable field, I get a background fill. I imagine this is under the window NSTextView responsibility. Has someone already succeeded in programming a totally transparent NSTextField, or shall I recourse to a CATextLayer instead?

    Thanks,
    Vincent
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today