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
committed by Magesh K
parent 4551451b57
commit df43561494

View File

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