Advertisement
anysome1ne

Untitled

Mar 31st, 2024 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.27 KB | None | 0 0
  1. import UIKit
  2. import SnapKit
  3.  
  4. class SubscribeScreenView: UIViewController {
  5.    
  6.     private let btnCancel = UIButton()
  7.    
  8.     private let titleLabel = UILabel()
  9.    
  10.     private var myCollectionView : UICollectionView!
  11.  
  12.     override func viewDidLoad() {
  13.         super.viewDidLoad()
  14.  
  15.         view.backgroundColor = .back
  16.         setupUI()
  17.     }
  18.    
  19.     @objc func cancelView() {
  20.        
  21.         dismiss(animated: true)
  22.        
  23.     }
  24.  
  25. }
  26.  
  27.  
  28. extension SubscribeScreenView {
  29.    
  30.     private func setupFlowLayout() -> UICollectionViewFlowLayout {
  31.        
  32.         let layout = UICollectionViewFlowLayout()
  33.        
  34.         layout.itemSize = .init(width: 300, height: 100)
  35.         layout.scrollDirection = .vertical
  36.        
  37.         return layout
  38.        
  39.     }
  40.    
  41.     private func setupUI() {
  42.        
  43.         myCollectionView = UICollectionView(frame: .zero, collectionViewLayout: setupFlowLayout())
  44.        
  45.         [myCollectionView].forEach { view.addSubview($0) }
  46.         [titleLabel, btnCancel].forEach { myCollectionView.addSubview($0) }
  47.        
  48.         myCollectionView.snp.makeConstraints { make in
  49.             make.top.equalToSuperview()
  50.             make.leading.equalToSuperview()
  51.             make.trailing.equalToSuperview()
  52.             make.bottom.equalToSuperview()
  53.            
  54.         }
  55.        
  56.         titleLabel.snp.makeConstraints { make in
  57.             make.top.equalToSuperview().inset(100)
  58.             make.leading.equalToSuperview().inset(20)
  59.         }
  60.        
  61.         btnCancel.snp.makeConstraints { make in
  62.             make.top.equalToSuperview().inset(-100)
  63.             make.trailing.equalToSuperview().inset(20)
  64.             make.height.equalTo(titleLabel.snp.height)
  65.             make.width.equalTo(60)
  66.         }
  67.                
  68.         // setup
  69.        
  70.         myCollectionView.dataSource = self
  71.         myCollectionView.delegate = self
  72.         myCollectionView.backgroundColor = .back
  73.         myCollectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "testID")
  74.                
  75.         titleLabel.text = "Подписки TLG"
  76.         titleLabel.font = UIFont(name: "Lato-Black", size: 30)
  77.         titleLabel.textAlignment = .left
  78.         titleLabel.textColor = .accent
  79.         titleLabel.adjustsFontSizeToFitWidth = true
  80.         titleLabel.minimumScaleFactor = 0.1
  81.         titleLabel.numberOfLines = 2
  82.        
  83.         btnCancel.setImage(UIImage(systemName: "xmark"), for: .normal)
  84.         btnCancel.imageView?.tintColor = .white
  85.         btnCancel.addTarget(self, action: #selector(cancelView), for: .touchUpInside)
  86.        
  87.        
  88.        
  89.     }
  90.    
  91. }
  92.  
  93. extension SubscribeScreenView : UICollectionViewDataSource, UICollectionViewDelegate {
  94.    
  95.     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  96.         20
  97.     }
  98.    
  99.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  100.        
  101.         guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "testID", for: indexPath) as? UICollectionViewCell else { fatalError() }
  102.        
  103.         cell.backgroundColor = UIColor.accent
  104.        
  105.         return cell
  106.        
  107.     }
  108.    
  109.    
  110.    
  111.    
  112. }
  113.  
Tags: swift
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement