Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gray border when using NSBorderlessWindowMask

Tags:

macos

cocoa

Whenever I try to create a custom window using NSBorderlessWindowMask and set an NSView (for example an NSImageView) as its contentView, I get a 1px gray border around the NSView and I don't seem to be able to get rid of it.

I have followed several approaches including Apple's RoundTransparentWindow sample code as well as several suggestions on StackOverflow.

I suspect the gray border is either coming from the window itself or the NSView.

Have any of you experienced this problem or do you have a possible solution?

The code is fairly straightforward. This is the init method of the custom window:

- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
    self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];

    if (self != nil) {
        [self setAlphaValue:1.0];
        [self setBackgroundColor:[NSColor clearColor]];     
        [self setOpaque:NO];
    }

    return self;
}

To test this, in IB I place an NSImageView in that custom window WITHOUT border and yet the image in the NSImageView has a border. The same goes for other NSView subclasses, such as NSTextField, NSTableView.

In addition, I also noticed that the same is happening with the sample application (RoundTransparentWindow) of Apple. Is it even possible to draw an NSView in a custom window without a 1px border?

Thanks

like image 241
Bart Jacobs Avatar asked Jun 04 '26 18:06

Bart Jacobs


1 Answers

Are you sure this happens when you use a regular NSView with no drawing? I bet not. Other controls (like NSImageView)have borders. Maybe you should double check to make sure they're turned off whe possible.

Update - How do you get your view into your window? You don't include that code. I created a basic test project (download it here) with an image well and it works just fine. See for yourself.

like image 141
Joshua Nozzi Avatar answered Jun 07 '26 13:06

Joshua Nozzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!