Update: As of WWDC 2017, tvOS supports non-roundrect buttons. Here's a link to the documentation.
Original question:
On tvOS, the system-type UIButton
gets a neat shadow effect when it's in focus.
I'd like to get this effect, but with a rounded UIButton
. So far, I've tried the following:
I've tried rounding the corners with the ol' layer.cornerRadius
trick - but this doesn't work; the buttons are round but they do not lift off the view when focused (because they're clipping to bounds):
button.layer.cornerRadius = button.size.width / 2.0
button.clipsToBounds = true
I've tried setting a circular background image - but now there's a weird background color or shadow appearing behind the buttons:
button.setBackgroundImage(myCircularImage, forState: .Normal)
Here's what Option 2 looks like (note: the red button is currently focused):
Is there something else I can try with UIButton(type: .System)
to get the Focus Engine's shadow effect for free? Or do I need to write something more custom for this?
I spoke with Apple engineers at the tvOS talks in Seattle this month - there is currently no way to get the system-standard Focus behaviors (parallax, motion effects, shine, etc) for round UIButtons - which is a bummer!
They recommended that I either change the design, or write my own focus/parallax/motion effects for the UIButton. I'm not eager to write my own - it's probably not possible to fully replicate the system-standard effects, and when the platform changes in the future, the custom effects will probably look dated.
Update: I've written up a blog post and included sample code for accomplishing this effect: http://www.devsign.co/notes/custom-focus-effects-in-tvos
Update #2: As of WWDC 2017, tvOS supports non-roundrect buttons! Here's Apple's documentation.