Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import SnapKit
- class SubscribeScreenView: UIViewController {
- private let btnCancel = UIButton()
- private let titleLabel = UILabel()
- private var myCollectionView : UICollectionView!
- override func viewDidLoad() {
- super.viewDidLoad()
- view.backgroundColor = .back
- setupUI()
- }
- @objc func cancelView() {
- dismiss(animated: true)
- }
- }
- extension SubscribeScreenView {
- private func setupFlowLayout() -> UICollectionViewFlowLayout {
- let layout = UICollectionViewFlowLayout()
- layout.itemSize = .init(width: 300, height: 100)
- layout.scrollDirection = .vertical
- return layout
- }
- private func setupUI() {
- myCollectionView = UICollectionView(frame: .zero, collectionViewLayout: setupFlowLayout())
- [myCollectionView].forEach { view.addSubview($0) }
- [titleLabel, btnCancel].forEach { myCollectionView.addSubview($0) }
- myCollectionView.snp.makeConstraints { make in
- make.top.equalToSuperview()
- make.leading.equalToSuperview()
- make.trailing.equalToSuperview()
- make.bottom.equalToSuperview()
- }
- titleLabel.snp.makeConstraints { make in
- make.top.equalToSuperview().inset(100)
- make.leading.equalToSuperview().inset(20)
- }
- btnCancel.snp.makeConstraints { make in
- make.top.equalToSuperview().inset(-100)
- make.trailing.equalToSuperview().inset(20)
- make.height.equalTo(titleLabel.snp.height)
- make.width.equalTo(60)
- }
- // setup
- myCollectionView.dataSource = self
- myCollectionView.delegate = self
- myCollectionView.backgroundColor = .back
- myCollectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "testID")
- titleLabel.text = "Подписки TLG"
- titleLabel.font = UIFont(name: "Lato-Black", size: 30)
- titleLabel.textAlignment = .left
- titleLabel.textColor = .accent
- titleLabel.adjustsFontSizeToFitWidth = true
- titleLabel.minimumScaleFactor = 0.1
- titleLabel.numberOfLines = 2
- btnCancel.setImage(UIImage(systemName: "xmark"), for: .normal)
- btnCancel.imageView?.tintColor = .white
- btnCancel.addTarget(self, action: #selector(cancelView), for: .touchUpInside)
- }
- }
- extension SubscribeScreenView : UICollectionViewDataSource, UICollectionViewDelegate {
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- 20
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "testID", for: indexPath) as? UICollectionViewCell else { fatalError() }
- cell.backgroundColor = UIColor.accent
- return cell
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement