1

I'm trying out some styling of NSTextFields to get Single Line Text Fields like the Material Design ones. With normal NSTextFields I have no problems, it works out pretty well. I'm subclassing the NSTextFieldCell and draw my custom cell (simply with a 1px border at the bottom).

The code is like this:

override func drawWithFrame(cellFrame: NSRect, inView controlView: NSView) {
        //let path:NSBezierPath = NSBezierPath.init(rect: cellFrame)
        //path.fill()
        var customRect = cellFrame
        customRect.origin.y = cellFrame.size.height - 1
        customRect.origin.x = 0;
        let usedColor:NSColor = NSColor.grayColor()
        usedColor.setFill()
        let path = NSBezierPath.init(rect: customRect)
        path.fill()
        
        super.drawWithFrame(cellFrame, inView: controlView);
    }

I'm adding the subclass in the interface builder and assign it to my TextField(Cell). Everything works fine with normal textfields.

But now I want to do the same with NSSecureTextFields, but the outcome is weird. The focus ring is visible, even though I set it to NONE.

The source code of the NSSecureTextFieldCell is the same as the one above (of course with the difference that I subclassed NSSecureTextFieldCell and not NSTextFieldCell), but why doesn't it show me the line at the bottom of the cell? And why do I get the damn focus ring when I assign my CustomCell-Class to the Cell? I just don't understand it and that makes me nuts.

Download Xcode Project File here (36 KB)

  • I had the same issue with `NSSecureTextField` ignoring the focus ring type I set in _interface builder_. However, if I set the focus ring type on the `NSSecureTextField` _programmatically_ then it worked fine. – Adam Johns Apr 28 '16 at 14:44

2 Answers2

1

You can use the following code to remove the focus ring in the viewDidLoad

self.SecuredTextField.focusRingType = NSFocusRingType.None

Barath
  • 1,656
  • 19
  • 19
0

I had the same issue and I solved it by using a standard NSTextField with a NSSecureTextFieldCell subclass as its cell class.

Reda Lemeden
  • 1,017
  • 1
  • 10
  • 16