9

As the title says, I actually want to remove the border from an NSBrowser control. The parents are NSView and NSControl. There's no available methods in NSBrowser itself, and neither in the parent controls. This one seems completely undocumented.

As to the reason for removing the border, because it's programatically docked into another view, so the view hierarchy means there's a border already.

Any ideas?

Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Kieran Senior
  • 17,960
  • 26
  • 94
  • 138

5 Answers5

3

Just embed it a plain NSView ("Custom View" in IB) and make the browser's frame "outset" by 1 point in all directions from the containing view's bounds. The containing view will clip the browser to eliminate the border. Then place that containing view into the surrounding view hierarchy, rather than adding the browser directly.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154
  • None of the other answers worked for me. I implemented this answer by setting all four of the auto layout constraints of the NSBrowser to -1 to the superview (the enclosing plain NSView). Works like a champ. – Chuck H Dec 04 '16 at 04:03
2

NSBrowser uses NSBrowserCell to implement its interface. That inherits from NSCell. NSCell should provide the methods you need.

From NSCell class reference... Managing Display Attributes – setBezeled: – isBezeled – setBordered: – isBordered – isOpaque – setControlTint: – controlTint – setBackgroundStyle: – backgroundStyle – interiorBackgroundStyle

uchuugaka
  • 12,679
  • 6
  • 37
  • 55
1

Remove the border on the NSScrollView that it is enclosed in.

Aditya Vaidyam
  • 6,259
  • 3
  • 24
  • 26
  • That's the first thing I looked into. There's no available options. The documents expose the border enum options, but there's no method to set the border. – Kieran Senior Feb 12 '13 at 09:44
  • That's odd... IB can definitely do that. Let me have a look, then. – Aditya Vaidyam Feb 12 '13 at 23:52
  • As far as I am aware `NSBrowser` has a different setup to most scrollable components in AppKit. Rather than be enclosed in a scroll view (like `NSTableView` expects for example), it instead provides its own internal scroll view(s). – Mike Abdullah Oct 16 '13 at 10:55
1

Neither of existing answers worked for me.

  • Embedding in NSView looked like an acceptable workaround, but it clips the browser.
  • NSScrollView isn't superclass of NSBrowser.
  • Layer is not used for this border, it's nil.
  • NSBrowserCell has nothing to do with NSBrowser's border.

Use borderType: NSBorderType property (same as in some other classes), setting it in Interface Builder. In Identity Inspector (++3) add to User Defined Runtime Attributes:

Key Path: borderType
Type: Number
Value: 0 (corresponds to NSBorderType.noBorder)

stasswtf
  • 153
  • 1
  • 6
  • This worked for me. It looks like on Big Sur the NSScrollView used by the NSBrowser no longer has a border by default. I used this method to enable the bezel border (value 2) on the NSBrowser. Tested on 10.13, 10.15, and Big Sur Beta 9. – duncanc4 Oct 01 '20 at 10:27
0

For those, who still looking for a solution. NSBrowser is the subclass of NSView. You can set an NSView layer's border width to 0:

(Swift)

self.layer?.borderWidth = 0
Ales Tsurko
  • 75
  • 2
  • 4