forked from zelo72/mastodon-ios
109 lines
3.7 KiB
Swift
109 lines
3.7 KiB
Swift
//
|
|
// SearchRecommendCollectionHeader.swift
|
|
// Mastodon
|
|
//
|
|
// Created by sxiaojian on 2021/4/1.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class SearchRecommendCollectionHeader: UIView {
|
|
let titleLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.textColor = Asset.Colors.Label.primary.color
|
|
label.font = .systemFont(ofSize: 20, weight: .semibold)
|
|
return label
|
|
}()
|
|
|
|
let descriptionLabel: UILabel = {
|
|
let label = UILabel()
|
|
label.textColor = Asset.Colors.Label.secondary.color
|
|
label.font = .preferredFont(forTextStyle: .body)
|
|
label.numberOfLines = 0
|
|
label.lineBreakMode = .byWordWrapping
|
|
return label
|
|
}()
|
|
|
|
let seeAllButton: HighlightDimmableButton = {
|
|
let button = HighlightDimmableButton(type: .custom)
|
|
button.setTitleColor(Asset.Colors.brandBlue.color, for: .normal)
|
|
button.setTitle(L10n.Scene.Search.Recommend.buttonText, for: .normal)
|
|
return button
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: .zero)
|
|
configure()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
configure()
|
|
}
|
|
}
|
|
|
|
extension SearchRecommendCollectionHeader {
|
|
private func configure() {
|
|
backgroundColor = .clear
|
|
translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
let containerStackView = UIStackView()
|
|
containerStackView.axis = .vertical
|
|
containerStackView.layoutMargins = UIEdgeInsets(top: 31, left: 16, bottom: 16, right: 16)
|
|
containerStackView.isLayoutMarginsRelativeArrangement = true
|
|
containerStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
addSubview(containerStackView)
|
|
NSLayoutConstraint.activate([
|
|
containerStackView.topAnchor.constraint(equalTo: topAnchor),
|
|
containerStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor)
|
|
])
|
|
|
|
let horizontalStackView = UIStackView()
|
|
horizontalStackView.axis = .horizontal
|
|
horizontalStackView.alignment = .center
|
|
horizontalStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
horizontalStackView.distribution = .fill
|
|
titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
titleLabel.setContentHuggingPriority(.defaultLow - 1, for: .horizontal)
|
|
horizontalStackView.addArrangedSubview(titleLabel)
|
|
seeAllButton.translatesAutoresizingMaskIntoConstraints = false
|
|
horizontalStackView.addArrangedSubview(seeAllButton)
|
|
|
|
containerStackView.addArrangedSubview(horizontalStackView)
|
|
descriptionLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
containerStackView.addArrangedSubview(descriptionLabel)
|
|
|
|
}
|
|
}
|
|
|
|
#if canImport(SwiftUI) && DEBUG
|
|
import SwiftUI
|
|
|
|
struct SearchRecommendCollectionHeader_Previews: PreviewProvider {
|
|
static var controls: some View {
|
|
Group {
|
|
UIViewPreview {
|
|
let cell = SearchRecommendCollectionHeader()
|
|
cell.titleLabel.text = "Trending in your timeline"
|
|
cell.descriptionLabel.text = "Hashtags that are getting quite a bit of attention among people you follow"
|
|
cell.seeAllButton.setTitle("See All", for: .normal)
|
|
return cell
|
|
}
|
|
.previewLayout(.fixed(width: 320, height: 116))
|
|
}
|
|
}
|
|
|
|
static var previews: some View {
|
|
Group {
|
|
controls.colorScheme(.light)
|
|
controls.colorScheme(.dark)
|
|
}
|
|
.background(Color.gray)
|
|
}
|
|
}
|
|
|
|
#endif
|