Advertisement
srk72

Tabbar with mutliselection and animation

Feb 15th, 2023
1,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.46 KB | None | 0 0
  1.  
  2.  
  3.  
  4.     @objc private func selection(button: UIButton) {
  5.        
  6.         nearbyBut.setTitleColor(#colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1), for: .normal)
  7.         nearbyBut.imageView?.tintColor = #colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1)
  8.        
  9.         popularBut.setTitleColor(#colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1), for: .normal)
  10.         popularBut.imageView?.tintColor = #colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1)
  11.        
  12.         onlineBut.setTitleColor(#colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1), for: .normal)
  13.         onlineBut.imageView?.tintColor = #colorLiteral(red: 0.5960784314, green: 0.5960784314, blue: 0.5960784314, alpha: 1)
  14.        
  15.         tableTitle.fadeTransition(0.5)
  16.        
  17.         switch button {
  18.         case nearbyBut:
  19.             currentList = .nearby
  20.             nearbyBut.setTitleColor(.blueColor, for: .normal)
  21.             nearbyBut.imageView?.tintColor = .blueColor
  22.             tableTitle.text = "Nearby Tutor"
  23.         case popularBut:
  24.             currentList = .popular
  25.             popularBut.setTitleColor(.blueColor, for: .normal)
  26.             popularBut.imageView?.tintColor = .blueColor
  27.             tableTitle.text = "Pupular Tutor"
  28.         case onlineBut:
  29.             currentList = .all
  30.             onlineBut.setTitleColor(.blueColor, for: .normal)
  31.             onlineBut.imageView?.tintColor = .blueColor
  32.             tableTitle.text = "All Tutor"
  33.         default:
  34.             debugPrint("default!")
  35.         }
  36.        
  37.         changeSelection(selected: currentList)
  38.         UIView.transition(with: tutorTable, duration: 0.8, options: .transitionCrossDissolve, animations: {self.tutorTable.reloadData()}, completion: nil)
  39.     }
  40.    
  41.     private func changeSelection(selected: TutorSelection) {
  42.        
  43.         indicatorCenter.isActive = false
  44.         indicatorTrailing.isActive = false
  45.         indicatorLeading.isActive = false
  46.        
  47.         switch selected {
  48.         case .all:
  49.             indicatorLeading.isActive = true
  50.         case .nearby:
  51.             indicatorCenter.isActive = true
  52.         case .popular:
  53.             indicatorTrailing.isActive = true
  54.         }
  55.        
  56.         UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveLinear) {
  57.             self.view.layoutIfNeeded()
  58.         }
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement