Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSWindow with round corners in swift

Tags:

macos

swift

cocoa

I want a window with a rounded corners. But I get a white spot in every corner.

Code:

let effect = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 0, height: 0))
effect.blendingMode = .behindWindow
effect.state = .active
effect.material = .dark
effect.wantsLayer = true
effect.layer?.cornerRadius = 15.0
window.contentView = effect
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden

Output:

enter image description here

How to get rid of those white spot in the corners?

like image 965
ssh Avatar asked Mar 13 '17 11:03

ssh


People also ask

How do you make rounded corners in swift?

Make UIImageView Corners RoundedSetting the corner radius to 100 will make the image view completely rounded. Try different corner radius like 10, 20, 30, 40 to get image corners of different radius. To make the image border and visible I will set the borderWidth and the borderColor.

How do you round UIView corners?

If you start with a regular UIView it has square corners. You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.

How do I give an image a corner radius in Swift?

To make an image with round corners or to make any view or button or any UI element with round corners in swift, we need to access the corner radius property of its layer. Every UI element in iOS is based on a layer. First of all, let's add an UIImageView Object in our storyboard. Or let's create one programmatically.


1 Answers

Also add this code to your code

window.isOpaque = false
window.backgroundColor = .clear

I don't have my machine to check but once I had the same issue and I think I resolved it by using above code. I will check when I get back to my machine.

Give it a shot and update me.

like image 127
SkrewEverything Avatar answered Sep 19 '22 11:09

SkrewEverything