Skip to content

Instantly share code, notes, and snippets.

@zenangst
Last active April 14, 2021 21:33
Show Gist options
  • Save zenangst/56d4b61dd62f3c58bffdbd3171947b59 to your computer and use it in GitHub Desktop.
Save zenangst/56d4b61dd62f3c58bffdbd3171947b59 to your computer and use it in GitHub Desktop.
Round corners for image views on tvOS (Swift 4)
// 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
}
}
@zenangst
Copy link
Author

zenangst commented Jun 2, 2020

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