In a Cocoa Swift macOS application, is there a way to subclass AVPlayerView to get round corners and a shadow?

95 views Asked by At

I have a Cocoa Swift macOS application that I am developing. I would like to obtain an AVPlayerView with round corners and a shadow. If I enable the shadow in interface builder it shows correctly there but not when I run the app, and drawRect in my subclass is never called so I don't have a clue to where to draw round corners. Any help is much appreciated. Thanks

2

There are 2 answers

0
ekscrypto On BEST ANSWER

You could put the AVPlayerView inside a container view, and apply the cornerRadius and maskToBounds on that view instead of trying to subclass AVPlayerView itself.

0
Ely On

In case it's just about getting rounded corners, you can use this code:

playerView.wantsLayer = true
playerView.layer?.cornerRadius = 10
playerView.layer?.masksToBounds = true

In this code, playerView is an NSPlayerView object.