69 lines
2.2 KiB
Swift
69 lines
2.2 KiB
Swift
//
|
|
// SubscriptionsHeaderTableViewCell.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 29/07/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
|
|
class SubscriptionsHeaderTableViewCell: UITableViewHeaderFooterView {
|
|
|
|
// MARK: - UI
|
|
|
|
private lazy var headerTitleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.font = UIFont.preferredFont(forTextStyle: .title2)
|
|
label.textColor = AppTheme.Colors.darkGray
|
|
label.textAlignment = .center
|
|
return label
|
|
}()
|
|
|
|
private lazy var loadingActivityIndicator: UIActivityIndicatorView = {
|
|
let spinner = UIActivityIndicatorView(style: .medium)
|
|
spinner.translatesAutoresizingMaskIntoConstraints = false
|
|
spinner.hidesWhenStopped = true
|
|
return spinner
|
|
}()
|
|
|
|
// MARK: - Init
|
|
|
|
override init(reuseIdentifier: String?) {
|
|
super.init(reuseIdentifier: reuseIdentifier)
|
|
setupUI()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
setupUI()
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func setupUI() {
|
|
contentView.addSubview(headerTitleLabel)
|
|
contentView.addSubview(loadingActivityIndicator)
|
|
|
|
headerTitleLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
|
|
headerTitleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: .cardPadding).isActive = true
|
|
headerTitleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: .cardPadding.negative).isActive = true
|
|
loadingActivityIndicator.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: .cardPadding.negative).isActive = true
|
|
loadingActivityIndicator.centerYAnchor.constraint(equalTo: headerTitleLabel.centerYAnchor).isActive = true
|
|
}
|
|
|
|
// MARK: - Public
|
|
|
|
func update(isLoading: Bool, title: String?) {
|
|
headerTitleLabel.text = title
|
|
|
|
if isLoading && title != nil {
|
|
loadingActivityIndicator.startAnimating()
|
|
} else {
|
|
loadingActivityIndicator.stopAnimating()
|
|
}
|
|
}
|
|
}
|