NSView Border Color

i am applying a border to NSView but how can i change the bordercolor. Using NSColor with setBorderColor is showing a warning. I want to use Orange Color in Border

    [self setWantsLayer:YES];
    self .layer.masksToBounds   = YES;    
    self.layer.borderWidth      = 6.0f ;

    [self.layer setBorderColor:CGColorGetConstantColor(kCGColorBlack)]; 

How can i set other colors(excluding black and white) in Border

Regards, Haseena

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

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

How to draw a dash line border for NSView, This is OK to set border line and color for my NSView, but i want to set a dash line , anyone know how to do this? And i tried some codes from the web search, but� For example, you might add color to the lines or background, add a new line style, or have the views in the group automatically snap to an invisible grid when added. Methods to Override. You must override the draw(_:) method (inherited from NSView) if you want to customize the appearance of your NSBox objects.

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

cocoa - NSView Border Color, i am applying a border to NSView but how can i change the bordercolor. Using NSColor with setBorderColor is showing a warning. I want to use Orange Color in � To receive the latest developer news, visit and subscribe to our News and Updates.

Wow... so simple these days. In your NSView when created:

self.wantsLayer = YES;
self.layer.borderWidth = 1;

Then in drawRect (so that you can respond to changes for dark mode or other Appearances) set the border color.... and DON'T Forget to use system colors that respond to Appearance changes or colors you define in Asset catalog that support all appearances you support.

    self.layer.borderColor = [NSColor systemGrayColor];
    // or color defined in Asset Catalog
    self.layer.borderColor = [NSColor colorNamed:@"BorderColor"].CGColor;
    [super drawRect:rect];

It's that simple.

NSView, window returns the NSWindow object that contains the NSView object. Returns a Boolean value indicating whether the view is being drawn to an environment that supports color. These constants specify the type of a view's border. DejalBackgroundView is a NSView subclass to provide a background color and/or border color to a view. Donations. I wrote DejalBackgroundView for my own use, but I'm making it available for the benefit of the Mac developer community. If you find it useful, a donation via PayPal (or something from my Amazon.com Wish List) would be very much

Setting a background color to an NSView, macOS (formerly known as OS X) development has always been a passion project for me; it is what made get into app development in the first� Color Well. Cocoa provides a nice control to let users access the Colors system panel and pick a color to use in the app. This control is called Color Well and it can be found in the Objects Library along with the rest of controls. Go and add such a control to the view (using frame 20, 60, 100, 100), and then open the Attributes Inspector.

NSView Border Color - cocoa - iOS, i am applying a border to NSView but how can i change the bordercolor. Using NSColor with setBorderColor is showing a warning. I want to use Orange Color in � Presto! A configurable border radius on any UIView you create. IBDesignable. As if that weren’t enough, IBDesignable custom views also debut in Xcode 6. When applied to a UIView or NSView subclass, the @IBDesignable designation lets Interface Builder know that it should render the view directly in the canvas. This allows seeing how your

How to add a border outline color to a UIView, borderColor = UIColor.red.cgColor. Note that you need to use the cgColor property of your UIColor in order for this to work. Adding a border to a� Set the drawing attributes: line width, fill color and border color. Add the path to the context and draw it using the .fillStroke parameter, which tells Core Graphics to fill the rectangle and draw the border. You’ll never look at a rectangle the same way! Here’s the humble result of all that code:

  • There is a category for AppKit that does a conversion from NSColor to CGColor here: gist.github.com/707921. It might worth a look.
  • You need to use NSBox, which is a subclass of NSView