mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
`icon` approximates the rounded corners of an app icon, while `circular` makes the icon a circle.
56 lines
1.1 KiB
Swift
56 lines
1.1 KiB
Swift
//
|
|
// AppIconImageView.swift
|
|
// AltStore
|
|
//
|
|
// Created by Riley Testut on 5/9/19.
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension AppIconImageView
|
|
{
|
|
enum Style
|
|
{
|
|
case icon
|
|
case circular
|
|
}
|
|
}
|
|
|
|
class AppIconImageView: UIImageView
|
|
{
|
|
var style: Style = .icon {
|
|
didSet {
|
|
self.setNeedsLayout()
|
|
}
|
|
}
|
|
|
|
override func awakeFromNib()
|
|
{
|
|
super.awakeFromNib()
|
|
|
|
self.contentMode = .scaleAspectFill
|
|
self.clipsToBounds = true
|
|
self.backgroundColor = .white
|
|
|
|
self.layer.cornerCurve = .continuous
|
|
}
|
|
|
|
override func layoutSubviews()
|
|
{
|
|
super.layoutSubviews()
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|