ios 如何自定义FSCalendar

4ktjp1zp  于 2023-04-08  发布在  iOS
关注(0)|答案(4)|浏览(296)

我正在使用FSCalendar https://github.com/WenchaoIOS/FSCalendar我有一个按钮在我的VC和FSCalendar在UIView如果我点击按钮,我需要显示当前日期(像谷歌日历应用程序的东西)我怎么能做到这一点?

ktca8awb

ktca8awb1#

你可以调用日历selectDate与今天的日期在按钮的行动。如下所示:

NSDate *today = [NSDate date];
[calendar setDate: today];

当您点击按钮时,这将滚动到今天的动画,并选择它。
希望这能帮上忙。

bis0qfac

bis0qfac2#

如果你想显示今天的月份。

calendar.currentPage = [NSDate date];

如果您想'选择'今天并显示今天的月份

[calendar selectDate:[NSDate date]];
68de4m5k

68de4m5k3#

Button Action:    

- (void)backToToday {
// scroll to page date
self.currentPageDate = self.today;
// default selected date
self.selectedDate = self.today;

self.calendar.currentPage = self.currentPageDate;
[self.calendar selectDate:self.selectedDate scrollToDate:NO];
}

dm7nw8vv

dm7nw8vv4#

程序化创建FSCalendar并自定义

var calendar: FSCalendar!

override func viewDidLoad() {
    calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: self.calendarView.frame.width, height: self.calendarView.frame.height))
        calendar.alpha = 1
        calendar.center = calendarView.center

    calendar.headerHeight = 0
        calendar.placeholderType = .none
        calendar.appearance.weekdayTextColor = .lightGray    //   weekday text color
        calendar.appearance.titleDefaultColor = .white   //   active dates color
        calendar.appearance.titleSelectionColor = .black    //   selected date text color
        calendar.appearance.titleTodayColor = .black    //  todays date text color
        calendar.appearance.todayColor = .white   // todays date circle color
        calendar.appearance.selectionColor = .lightGray   //   date selection color
        calendarView.addSubview(calendar)
        calendarCurrentPageDidChange(calendar)
}

从FSCalendar显示当前月份名称

func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
        let currentPageDate = calendar.currentPage
        let month = Calendar.current.component(.month, from: currentPageDate)
        let monthName = DateFormatter().monthSymbols[month - 1].capitalized      // Get current month name to display separately 
        monthLbl.setTitle(monthName, for: .normal)
  }

FSCalendar委托功能

func maximumDate(for calendar: FSCalendar) -> Date {
        var dateComponents:DateComponents = DateComponents()
        dateComponents.month = 12            // maximum month to display in calendar
        let currentCalander:Calendar = Calendar.current
        return currentCalander.date(byAdding:dateComponents, to: Date())!
}
    
func minimumDate(for calendar: FSCalendar) -> Date {
        var dateComponents:DateComponents = DateComponents()
        dateComponents.month = 0             // minimum month to display in calendar
        let currentCalander:Calendar = Calendar.current
        return currentCalander.date(byAdding:dateComponents, to: Date())!
}

func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
        self.scrollToDate(date.date)
 }

使用FSCalendar的事件列表-使用UIButton显示和隐藏日历
https://stackoverflow.com/a/75887245/15716725

相关问题