5

I'm using an NSPopover and I'm putting a NSViewController inside to be displayed as a custom view from a NSStatusItem. Most of the view controller displays correctly except for the NSButton that have a corner radius on them. There is some extra white leaking out where the rounded corners are being applied. Displaying the buttons within the actual app, this problem doesn't occur.

I feel it has to do something with the NSPopover appearance which I have set to "NSAppearanceNameAqua".

The NSButtons are within a NSView which are displayed in a NSTableView and are set to this style.

    self.createdButton.wantsLayer = true
    self.createdButton.layer?.backgroundColor = Utils.blackColor().CGColor
    self.createdButton.layer?.masksToBounds = true
    self.createdButton.layer?.cornerRadius = 5

enter image description here enter image description here

The top image is when the actual app is open. The bottom image is when the view controller is being shown within a NSPopover.

cmakthat
  • 201
  • 4
  • 7
  • What do you mean when you say "the top image is when the actual app is open" vs "the view controller is being shown within a NSPopover" ? So the app isn't open in the bottom image? – rocky Mar 23 '16 at 21:30
  • I am creating a NSStatusItem that appears in the top menu bar. When you click the icon from the menu bar, an NSPopover appears with the view controller containing those buttons. – cmakthat Mar 23 '16 at 23:00
  • One thing that I found is if you add your buttons programmatically in the contentViewController and then round them they will round correctly. However, linking the same buttons/views from Interface Builder in a Xib/Storyboard will not apply the correct rounding, at least that was what I experienced. Maybe a bug in AppKit? – zic10 May 20 '16 at 13:13
  • did you ever resolve this ? – Vince Feb 05 '18 at 12:56

1 Answers1

0

create corner radius using bezier path i.e.

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:view.bounds xRadius:3 yRadius:3];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = view.bounds;
    maskLayer.path = path.toCGPath;
    self.containerView.layer.mask = maskLayer;
hishboy
  • 339
  • 2
  • 10