Snippets Collections
@IBOutlet weak var dayPicker: UIPickerView!
     
var pickerData: [Int]!

  viewDidLoad(){
  setDayPicker()
  dayPicker.delegate = self
  dayPicker.dataSource = self
}
  
//MARK: - Day Picker

extension PostRequestViewController : UIPickerViewDelegate, UIPickerViewDataSource {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return pickerData.count
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        print("\(pickerData[row])")
            return "\(pickerData[row])"
        }
    
    func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
        let attributedString = NSAttributedString(string: String(pickerData[row]), attributes: [NSAttributedString.Key.foregroundColor : pickerView.hexStringToUIColor(hex: "FEDA22")])
        return attributedString
    }
    
    func setDayPicker () {
        let minDay = 1
              let maxDay = 90
              pickerData = Array(stride(from: minDay, to: maxDay + 1, by: 1))
    }
}
var imagePicker = UIImagePickerController()

func enableImageViewTapGesture()
    {
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(profileImageTapped(tapGesturerecognizer:)))
        profileImageView.isUserInteractionEnabled = true
        profileImageView.addGestureRecognizer(tapGestureRecognizer)
    }
    
    @objc func profileImageTapped(tapGesturerecognizer: UITapGestureRecognizer){

        if UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum){
            print("Button capture")
            imagePicker.delegate = self
            imagePicker.sourceType = .savedPhotosAlbum
            imagePicker.allowsEditing = true
            present(imagePicker, animated: true, completion: nil)
        }
        else {
            print("No NO")
        }
    }

extension SignupViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        
        if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
            
            profileImageView.layer.cornerRadius = profileImageView.bounds.width/2
            profileImageView.image = pickedImage
        }
        self.dismiss(animated: true, completion: nil)
    }
    
    func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        dismiss(animated: true, completion:nil)
    }
}

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension