Files
SideStore/SideStoreApp/Sources/SideStoreUIKit/Components/BannerCollectionViewCell.swift

53 lines
2.0 KiB
Swift
Raw Normal View History

//
// BannerCollectionViewCell.swift
// AltStore
//
// Created by Riley Testut on 3/23/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
import UIKit
@objc
2023-03-01 00:48:36 -05:00
final class BannerCollectionViewCell: UICollectionViewCell {
private(set) var errorBadge: UIView?
@IBOutlet private(set) var bannerView: AppBannerView!
2023-03-01 00:48:36 -05:00
override func awakeFromNib() {
super.awakeFromNib()
2023-03-01 00:48:36 -05:00
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
contentView.preservesSuperviewLayoutMargins = true
if #available(iOS 13.0, *) {
let errorBadge = UIView()
errorBadge.translatesAutoresizingMaskIntoConstraints = false
errorBadge.isHidden = true
self.addSubview(errorBadge)
2023-03-01 00:48:36 -05:00
// Solid background to make the X opaque white.
let backgroundView = UIView()
backgroundView.translatesAutoresizingMaskIntoConstraints = false
backgroundView.backgroundColor = .white
errorBadge.addSubview(backgroundView)
2023-03-01 00:48:36 -05:00
let badgeView = UIImageView(image: UIImage(systemName: "exclamationmark.circle.fill"))
badgeView.preferredSymbolConfiguration = UIImage.SymbolConfiguration(scale: .large)
badgeView.tintColor = .systemRed
errorBadge.addSubview(badgeView, pinningEdgesWith: .zero)
2023-03-01 00:48:36 -05:00
NSLayoutConstraint.activate([
errorBadge.centerXAnchor.constraint(equalTo: self.bannerView.trailingAnchor, constant: -5),
errorBadge.centerYAnchor.constraint(equalTo: self.bannerView.topAnchor, constant: 5),
2023-03-01 00:48:36 -05:00
backgroundView.centerXAnchor.constraint(equalTo: badgeView.centerXAnchor),
backgroundView.centerYAnchor.constraint(equalTo: badgeView.centerYAnchor),
backgroundView.widthAnchor.constraint(equalTo: badgeView.widthAnchor, multiplier: 0.5),
backgroundView.heightAnchor.constraint(equalTo: badgeView.heightAnchor, multiplier: 0.5)
])
2023-03-01 00:48:36 -05:00
self.errorBadge = errorBadge
}
}
}