NSWindow with round corners and shadow

Update I realised old approach was not able to create precise round corner. So I updated example to make precise round corner. window1.backgroundColor = NSColor.whiteColor() window1.opaque = false window1.styleMask = NSResizableWindowMask | NSTitledWindowMask | NSFullSizeContentViewWindowMask window1.movableByWindowBackground = true window1.titlebarAppearsTransparent = true window1.titleVisibility = .Hidden window1.showsToolbarButton = false window1.standardWindowButton(NSWindowButton.FullScreenButton)?.hidden = true window1.standardWindowButton(NSWindowButton.MiniaturizeButton)?.hidden = true window1.standardWindowButton(NSWindowButton.CloseButton)?.hidden = … Read more

How can I create Yosemite-style view with translucent/blurry background?

w00t! I’ve found example code that uses not-yet-documented view type: Set XIB’s deployment target to 10.10 Embed your view in NSVisualEffectView In Interface Builder’s settings for the view set appearance to “Vibrant Light/Dark”. There are other options, like blending “Behind Window” or “Within Window” (the latter requires layers). There’s also NSView method allowsVibrancy that you … Read more

Does NSView have anything analogous to UIView’s setNeedsLayout/layoutSubviews methods?

As of OSX 10.7: – (void)layout is equivalent to layoutSubviews There is now an identical setNeedsLayout. Override this method if your custom view needs to perform custom layout not expressible using the constraint-based layout system. In this case you are responsible for calling setNeedsLayout: when something that impacts your custom layout changes. You may not … Read more

How do I make an NSView move to the front of all NSViews

Here’s another way to accomplish this that’s a bit more clear and succinct: [viewToBeMadeForemost removeFromSuperview]; [self addSubview:viewToBeMadeForemost positioned:NSWindowAbove relativeTo:nil]; Per the documentation for this method, when you use relativeTo:nil the view is added above (or below, with NSWindowBelow) all of its siblings.

NSView’s bounds vs frame

From the View and Window Architecture Programming Guide for iOS: A view object tracks its size and location using its frame, bounds, and center properties: The frame property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system. The bounds property contains the bounds rectangle, which specifies … Read more

Layer-backed NSView rotation and skewed siblings

You’ve written that you tried “setNeedsDisplay”. Are you calling this method from the main thread? In one of my applications nothing happened if I called setNeedsDisplay from another thread. If you want to make sure the display is invalid, then use dispatch like so: dispatch_async(dispatch_get_main_queue(), ^{ [view setNeedsDisplay:YES]; }); Additionally have a look in your … Read more

Best way to change the background color for an NSView

Yeah, your own answer was right. You could also use Cocoa methods: – (void)drawRect:(NSRect)dirtyRect { // set any NSColor for filling, say white: [[NSColor whiteColor] setFill]; NSRectFill(dirtyRect); [super drawRect:dirtyRect]; } In Swift: class MyView: NSView { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // #1d161d NSColor(red: 0x1d/255, green: 0x16/255, blue: 0x1d/255, alpha: 1).setFill() dirtyRect.fill() } … Read more