[swift] FSCalendar에서 이벤트 클릭 시 액션 설정

FSCalendar는 iOS 앱에서 캘린더를 표시할 때 많이 사용되는 라이브러리입니다. FSCalendar를 사용하여 이벤트를 표시하고, 클릭 시 액션을 설정하는 방법을 알아보겠습니다.

FSCalendarDelegate를 구현하여 이벤트 클릭 시 액션을 설정할 수 있습니다. 먼저, FSCalendarDelegate 프로토콜을 채택한 클래스로 이벤트 클릭 시 호출될 메서드를 작성합니다.

import FSCalendar

class ViewController: UIViewController, FSCalendarDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: 320, height: 300))
        calendar.delegate = self
        
        // 캘린더 설정 등
        
        view.addSubview(calendar)
    }
    
    func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
        // 이벤트 클릭 시 호출될 동작을 작성합니다.
        print("Selected date: \(date)")
    }
}

위 코드에서 FSCalendarDelegate를 구현한 ViewController 클래스에서 calendar(_:didSelect:at:) 메서드를 정의하여 이벤트 클릭 시 호출될 동작을 작성합니다. 위의 예제에서는 선택된 날짜를 콘솔에 출력하도록 작성되어 있습니다.

주의할 점은, ViewController 클래스에서 calendar.delegate = self를 통해 delegate를 설정하는 부분을 잊지 않도록 합니다.

FSCalendarDelegate 프로토콜을 통해 다양한 이벤트와 동작을 설정할 수 있으니, 필요에 따라 해당 메서드를 활용하여 원하는 액션을 구현할 수 있습니다.

더 자세한 정보를 원하신다면, FSCalendar 공식 문서를 참조하시기 바랍니다.