// // WelcomeSliderViewController.swift // Learn Genie // // Created by Suraj Kumar Mandal on 19/08/21. // import UIKit class WelcomeSliderViewController: UIViewController { @IBOutlet weak var backgroundView: UIView! @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var contentLabel: UILabel! @IBOutlet weak var skipButton: UIButton! @IBOutlet weak var nextButton: UIButton! var currentPage = 1 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func viewWillAppear(_ animated: Bool) { setupUI() addGesture() } func setupUI() { //Skip button design skipButton.layer.borderWidth = 1 skipButton.layer.cornerRadius = 5 skipButton.layer.borderColor = UIColor.black.cgColor //Next button design nextButton.layer.borderWidth = 1 nextButton.layer.cornerRadius = 5 nextButton.layer.borderColor = UIColor.black.cgColor contentChange() } func addGesture() { let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:))) let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipes(_:))) leftSwipe.direction = .left rightSwipe.direction = .right view.addGestureRecognizer(leftSwipe) view.addGestureRecognizer(rightSwipe) } func contentChange() { if currentPage == 1 { backgroundView.backgroundColor = AppColor.onboarding1 imageView.image = UIImage(named: Constant.onboarding1) contentLabel.text = Helper.translateText(inputText: Constant.content1) nextButton.setTitle(Helper.translateText(inputText: Constant.Next), for: .normal) skipButton.isHidden = false } else if currentPage == 2 { backgroundView.backgroundColor = AppColor.onboarding2 imageView.image = UIImage(named: Constant.onboarding2) contentLabel.text = Helper.translateText(inputText: Constant.content2) nextButton.setTitle(Helper.translateText(inputText: Constant.Next), for: .normal) skipButton.isHidden = false } else if currentPage == 3 { backgroundView.backgroundColor = AppColor.onboarding3 imageView.image = UIImage(named: Constant.onboarding3) contentLabel.text = Helper.translateText(inputText: Constant.content3) nextButton.setTitle(Helper.translateText(inputText: Constant.GetStarted), for: .normal) skipButton.isHidden = true } } @objc func handleSwipes(_ sender: UISwipeGestureRecognizer) { if sender.direction == .left { print("Swipe left") // show the view from the right side if currentPage > 3 { currentPage += 1 contentChange() } } if sender.direction == .right { print("Swipe right") // show the view from the left side if currentPage > 1 { currentPage -= 1 contentChange() } } } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ @IBAction func nextButtonAction(_ sender: UIButton) { if sender.currentTitle == Constant.GetStarted { //Set Welcome slider status to false UserDefaults.standard.set(false, forKey: Constant.welcomeSlider) UserDefaults.standard.synchronize() //Navigate to login screen DispatchQueue.main.async { let loginVC = self.storyboard?.instantiateViewController(withIdentifier:"LoginViewController" ) as! LoginViewController self.navigationController?.pushViewController(loginVC, animated: true) } } else { currentPage += 1 contentChange() } } @IBAction func skipButtonAction(_ sender: UIButton) { //Set Welcome slider status to false UserDefaults.standard.set(false, forKey: Constant.welcomeSlider) UserDefaults.standard.synchronize() //Navigate to login screen DispatchQueue.main.async { let loginVC = self.storyboard?.instantiateViewController(withIdentifier:"LoginViewController" ) as! LoginViewController self.navigationController?.pushViewController(loginVC, animated: true) } } }