Zakman411
Zakman411

Reputation: 1764

NSRect rounded corners

Is there a simple way to add rounded corners to NSRect elements in Objective-C? Currently we're applying a PNG image that simulates corners to this:

NSRect newFrame = NSMakeRect(0, 0, size.width, size.height);

But, performance becomes an issue because there are many instances of this NSRect along with the image being rendered with Core Animation. Perhaps rendering a native NSRect with rounded edges would be better from a performance standpoint? Do said edges look smooth (anti-aliased) when rendered with Core Animation?

Upvotes: 0

Views: 1146

Answers (1)

CodaFi
CodaFi

Reputation: 43330

NSRect is a struct containing an NSPoint and an NSSize, so I think you mean anything that accepts NSRects (so subclasses of NSView). All NSView subclass layers respond appropriately to -cornerRadius (except something about NSScrollView).

self.view.layer.masksToBounds = YES;
self.view.layer.cornerRadius = 10.0;

Upvotes: 4

Related Questions