dev._.note

[Swift] FSCalendar 라이브러리 본문

Dev/SWIFT

[Swift] FSCalendar 라이브러리

Laena 2024. 3. 6. 21:39

FSCalendar

달력 구현 라이브러리

https://github.com/WenchaoD/FSCalendar

 

GitHub - WenchaoD/FSCalendar: A fully customizable iOS calendar library, compatible with Objective-C and Swift

A fully customizable iOS calendar library, compatible with Objective-C and Swift - WenchaoD/FSCalendar

github.com

 


설치방법

1. 코코아팟으로 설치하기

pod init

pod 'FSCalendar'

pod install

 

2. SPM으로 다운로드받기

 

xcode 상단 File → Add Package Dependencies

 

검색창에 'https://github.com/WenchaoD/FSCalendar' 입력 → 하단 Add Package

 


FSCalendar으로 구현한 화면 

 

사용법 주석정리

private func configureCalendarAppearance() {
    // 캘린더의 로케일 설정 (한국어로 설정)
    calendar.locale = Locale(identifier: "ko_KR")
    
    // 캘린더 헤더의 날짜 형식 설정 (예: "2023.01")
    calendar.appearance.headerDateFormat = "yyyy.MM"
    
    // 캘린더 헤더의 텍스트 색상 설정
    calendar.appearance.headerTitleColor = TDStyle.color.mainDarkTheme
    
    // 요일 텍스트의 색상 설정
    calendar.appearance.weekdayTextColor = .systemGray3
    
    // 일반 날짜 텍스트의 색상 설정
    calendar.appearance.titleDefaultColor = .black
    
    // 선택된 날짜의 배경 색상 설정
    calendar.appearance.selectionColor = UIColor(red: 230/255, green: 244/255, blue: 237/255, alpha: 1)
    
    // 오늘 날짜 텍스트의 색상 설정
    calendar.appearance.titleTodayColor = .black
    
    // 오늘 날짜의 배경 색상 설정 (투명하게 설정)
    calendar.appearance.todayColor = UIColor.clear
    
    // 선택된 날짜 텍스트의 색상 설정
    calendar.appearance.titleSelectionColor = UIColor.black
    
    // 날짜 텍스트의 폰트 설정
    calendar.appearance.titleFont = TDStyle.font.body(style: .regular)
    
    // 이벤트 점의 기본 색상 설정
    calendar.appearance.eventDefaultColor = TDStyle.color.mainDarkTheme
    
    // 선택된 날짜의 이벤트 점 색상 설정
    calendar.appearance.eventSelectionColor = TDStyle.color.mainDarkTheme
    
    // 헤더의 최소 투명도 설정 (0으로 설정하여 투명도 없음)
    calendar.appearance.headerMinimumDissolvedAlpha = 0.0
    
    // 캘린더의 배경 색상 설정
    calendar.backgroundColor = .white
    
    // 이전 달로 이동하는 버튼 설정
    let prevMonthButton = UIButton(type: .system)
    prevMonthButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
    prevMonthButton.tintColor = TDStyle.color.mainDarkTheme
    prevMonthButton.addTarget(self, action: #selector(goToPreviousMonth), for: .touchUpInside)
    
    // 다음 달로 이동하는 버튼 설정
    let nextMonthButton = UIButton(type: .system)
    nextMonthButton.setImage(UIImage(systemName: "chevron.right"), for: .normal)
    nextMonthButton.tintColor = TDStyle.color.mainDarkTheme
    nextMonthButton.addTarget(self, action: #selector(goToNextMonth), for: .touchUpInside)
    
    // 이전 달, 다음 달 버튼을 뷰에 추가
    view.addSubview(prevMonthButton)
    view.addSubview(nextMonthButton)
    
    // 이전 달 버튼의 위치 설정
    prevMonthButton.snp.makeConstraints { make in
        make.left.equalTo(calendar.snp.left).offset(15)
        make.centerY.equalTo(calendar.calendarHeaderView.snp.centerY)
    }
    
    // 다음 달 버튼의 위치 설정
    nextMonthButton.snp.makeConstraints { make in
        make.right.equalTo(calendar.snp.right).offset(-15)
        make.centerY.equalTo(calendar.calendarHeaderView.snp.centerY)
    }
}