Last active
April 14, 2021 21:33
-
-
Save zenangst/56d4b61dd62f3c58bffdbd3171947b59 to your computer and use it in GitHub Desktop.
Round corners for image views on tvOS (Swift 4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A Swift 4 version of https://gist.github.com/petergp/815ba3bf6b7280c2c01f | |
private class ImageView : UIImageView { | |
private class Layer: CALayer { | |
override func addSublayer(_ layer: CALayer) { | |
defer { super.addSublayer(layer) } | |
let cornerRadiusKey = "_cornerRadius" | |
guard let configuration = layer.value(forKey: "_configuration") as? NSObject, | |
configuration.responds(to: NSSelectorFromString(cornerRadiusKey)) else { | |
return | |
} | |
configuration.setValue(5, forKey: cornerRadiusKey) | |
} | |
} | |
override class var layerClass: AnyClass { | |
return Layer.self | |
} | |
} |
Interesting, we opted out from using this solution and reimplemented the parallax effect ourselves.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work on tvOS 13.4,
configuration.setValue(5, forKey: cornerRadiusKey)
isn't called.