NSView Border Color

You can use NSBox, which is a subclass of NSView and designed to handle these cases

let box = NSBox()
box.boxType = .custom
box.alphaValue = 1
box.borderColor = NSColor.red
box.borderType = .lineBorder
box.borderWidth = 4

You need to convert to a CGColorRef

NSColor *orangeColor = [NSColor orangeColor];

// Convert to CGColorRef
NSInteger numberOfComponents = [orangeColor numberOfComponents];
CGFloat components[numberOfComponents];
CGColorSpaceRef colorSpace = [[orangeColor colorSpace] CGColorSpace];    
[orangeColor getComponents:(CGFloat *)&components];    
CGColorRef orangeCGColor = CGColorCreate(colorSpace, components);

// Set border
self.view.layer.borderColor = orangeCGColor;

// Clean up
CGColorRelease(orangeCGColor);

Or if you can require 10.8+, use [aColor CGColor]

Tags:

Cocoa