Adds AppIconImageView.style to switch between icon and circular styles

`icon` approximates the rounded corners of an app icon, while `circular` makes the icon a circle.
This commit is contained in:
Riley Testut
2023-10-16 18:40:01 -05:00
parent cdfb55deeb
commit b43bdede74

View File

@@ -8,8 +8,23 @@
import UIKit import UIKit
extension AppIconImageView
{
enum Style
{
case icon
case circular
}
}
class AppIconImageView: UIImageView class AppIconImageView: UIImageView
{ {
var style: Style = .icon {
didSet {
self.setNeedsLayout()
}
}
override func awakeFromNib() override func awakeFromNib()
{ {
super.awakeFromNib() super.awakeFromNib()
@@ -25,8 +40,16 @@ class AppIconImageView: UIImageView
{ {
super.layoutSubviews() super.layoutSubviews()
// Based off of 60pt icon having 12pt radius. switch self.style
let radius = self.bounds.height / 5 {
self.layer.cornerRadius = radius case .icon:
// Based off of 60pt icon having 12pt radius.
let radius = self.bounds.height / 5
self.layer.cornerRadius = radius
case .circular:
let radius = self.bounds.height / 2
self.layer.cornerRadius = radius
}
} }
} }