Advertisement
srk72

Regularly needed Components

May 20th, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.21 KB | None | 0 0
  1. // Hide Keyboard
  2.  
  3. private var currentTextField: UITextField?
  4.  
  5.     func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  6.         textField.resignFirstResponder()
  7.         return true
  8.     }
  9.    
  10.     func textFieldDidBeginEditing(_ textField: UITextField) {
  11.         currentTextField = textField
  12.     }
  13.    
  14.     override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  15.         let touch = touches.first
  16.        
  17.         if touch?.view != mailField && touch?.view != nameField {
  18.             self.view.endEditing(true)
  19.         }
  20.     }
  21.  
  22.     @IBAction func logoutAction(_ sender: Any) {
  23.         resignField()
  24.        
  25.     }
  26.    
  27.     func resignField() {
  28.         if let currentTextField = currentTextField {
  29.             currentTextField.resignFirstResponder()
  30.         }
  31.     }
  32.  
  33.  
  34. // UiTextField corner redius & border
  35.  
  36.        mailField.layer.cornerRadius = 7
  37.         mailField.layer.borderWidth = 1.8
  38.         mailField.layer.borderColor = #colorLiteral(red: 0.8374180198, green: 0.8374378085, blue: 0.8374271393, alpha: 1).cgColor
  39.  
  40.  
  41.  
  42.  
  43. // Collection View , TableView Programmatically
  44.  
  45. var framesCollectionView: UICollectionView!
  46.         let layout = UICollectionViewFlowLayout()
  47.         layout.scrollDirection = .horizontal
  48.        
  49.         if UIDevice.current.userInterfaceIdiom == .pad {
  50.             fontSize = 17
  51.             layout.minimumLineSpacing = 0
  52.             layout.minimumInteritemSpacing = 0
  53.             layout.sectionInset = UIEdgeInsets(top: 0, left: self.view.bounds.width / 3, bottom: 0, right: 100)
  54.             layout.itemSize = CGSize(width: self.view.bounds.width / 11, height: temporaryCellCollectionHeight)
  55.         } else if UIDevice.current.userInterfaceIdiom == .phone {
  56.             fontSize = 12
  57.             layout.minimumLineSpacing = 0
  58.             layout.minimumInteritemSpacing = 0
  59.             layout.itemSize = CGSize(width: self.view.bounds.width / 4, height: temporaryCellCollectionHeight)
  60.         }
  61.        
  62.         framesCollectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
  63.         framesCollectionView.dataSource = self
  64.         framesCollectionView.delegate = self
  65.         framesCollectionView.translatesAutoresizingMaskIntoConstraints = false
  66.         framesCollectionView.showsHorizontalScrollIndicator = false
  67.         framesCollectionView.backgroundColor = #colorLiteral(red: 0.1333333333, green: 0, blue: 0.2862745098, alpha: 1)
  68.         framesCollectionView.register(CollageVideoFrameCell.self, forCellWithReuseIdentifier: "CollageVideoFrameCell")
  69.  
  70.     @objc func framesButPressed() {
  71.         self.view.addSubview(framesCollectionView)
  72.         let safeArea = self.view.safeAreaLayoutGuide
  73.        
  74.         framesCollectionView?.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -3).isActive = true
  75.         framesCollectionView?.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 10).isActive = true
  76.         framesCollectionView?.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -10).isActive = true
  77.         framesCollectionView?.heightAnchor.constraint(equalToConstant: temporaryCellCollectionHeight).isActive = true
  78.        
  79.         framesCollectionView.reloadData()
  80.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement