Cocoa Mac rounded corners (like Xcode 4)

Does anyone know how you can make a cocoa leaf with rounded corners as shown below?

Xcode 4 Rounded Sheet

Xcode 4 Sheet - Rounded Corners

I looked at everything, but I can not find anything on it. I’m not sure what I’m looking for is in the wrong place, or if it’s just not an ordinary practice. Any ideas?

+6
source share
2 answers

Edit: It turns out that this behavior is even simpler if you are targeting OS X Lion or later β€” just call [sheet setOpaque:NO] enough to include rounded corners.


This behavior is fairly easy to reproduce. Initialize your sheet as a transparent borderless window:

 self.sheet = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 300, 300) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered | NSTitledWindowMask defer:YES]; [self.sheet setOpaque:NO]; [self.sheet setBackgroundColor:[NSColor clearColor]]; 

Add custom view as slave mode:

 [[self.sheet contentView] addSubview:[[IFWindowView alloc] initWithFrame:[[self.sheet contentView] frame]]]; 

This custom view should make its drawing as follows:

 #define RADIUS 5.0 NSBezierPath *bezierPath = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(self.bounds.origin.x, self.bounds.origin.y + RADIUS, self.bounds.size.width, self.bounds.size.height) xRadius:RADIUS yRadius:RADIUS]; [[NSColor windowBackgroundColor] set]; // In production, use the appropriate color with alpha for transparency. [bezierPath fill]; 

Here is a sample code to demonstrate this in action: http://d.pr/l9DB

+9
source

As far as I can tell, this is a window property. If it is a panel, it has square corners, if a window, round corners. At least what happens under Mac OS cannot vouch for iOS.

0
source

Source: https://habr.com/ru/post/912353/


All Articles