👩🏻💻 오늘 공부한 내용
✅ Page Control ( 참고 사이트 )
- pageControl 선언
@IBOutlet weak var pageControl: UIPageControl!
- pageControl 초기 설정
pageControl.numberOfPages =
pageControl.currentPage =
pageControl.pageIndicatorTintColor =
pageControl.currentPageIndicatorTintColor =
imageView.image =
- 페이지 눌렀을 때 함수 구현
@IBAction func pageChanged(_ sender: Any) {
imageView.image =
}
- 전체 코드
class SelectWishViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var pageControl: UIPageControl!
override func viewDidLoad() {
super.viewDidLoad()
setPageControl()
}
func setPageControl(){
pageControl.numberOfPages = wishListViewModel.wishs[paramIndex].photo.count
pageControl.currentPage = 0
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.white
imageView.image = wishListViewModel.wishs[paramIndex].photo[0]
}
@IBAction func pageChanged(_ sender: Any) {
imageView.image = wishListViewModel.wishs[paramIndex].photo[pageControl.currentPage]
}
}
✅ ImageView에 Swipte Gesture ( 참고 사이트 )
- swipe gesture 초기 설정
imageView.isUserInteractionEnabled = true
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(SelectWishViewController.respondToSwipeGesture(_:)))
swipeLeft.direction = UISwipeGestureRecognizer.Direction.left
self.imageView.addGestureRecognizer(swipeLeft)
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(SelectWishViewController.respondToSwipeGesture(_:)))
swipeRight.direction = UISwipeGestureRecognizer.Direction.right
self.imageView.addGestureRecognizer(swipeRight)
- 제스쳐 함수 구현
@objc func respondToSwipeGesture(_ gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer{
switch swipeGesture.direction {
case UISwipeGestureRecognizer.Direction.left :
pageControl.currentPage += 1
imageView.image = wishListViewModel.wishs[paramIndex].photo[pageControl.currentPage]
case UISwipeGestureRecognizer.Direction.right :
pageControl.currentPage -= 1
imageView.image = wishListViewModel.wishs[paramIndex].photo[pageControl.currentPage]
default:
break
}
}
}
✅ 사파리 호출
@IBAction func linkButtonTapped(_ sender: Any) {
if let url = URL(string: wishListViewModel.wishs[paramIndex].link) {
UIApplication.shared.open(url, options: [:])
}
}