iOS Development

ios – change choice colour in FSCalenar in swiftui

Spread the love


struct CustomCalendar: UIViewRepresentable {
   
    typealias UIViewType = FSCalendar
    
    @Binding var calendarModel : CalendarModel
    @Binding var pageCurrent: Date
    var calendar = FSCalendar()
func makeUIView(context: Context) -> FSCalendar {
        calendar.delegate = context.coordinator
        calendar.dataSource = context.coordinator
        calendar.allowsMultipleSelection = true;
        calendar.scope = .month
        calendar.firstWeekday = 1
        calendar.look.borderRadius = 20
        calendar.in the present day = nil
        calendar.look.weekdayTextColor = .black
        calendar.clipsToBounds = true
        calendar.look.weekdayTextColor = .grey
        calendar.locale =  Locale(identifier: "en_US")
        calendar.calendarHeaderView.isHidden = true
        calendar.headerHeight = 0.0
        context.coordinator.setRangeToCalender(from: calendarModel.startDay, to: calendarModel.endDay) ///set rang to calendar when name edit
      
       
        return calendar
    }
    
    func updateUIView(_ uiView: FSCalendar, context: Context) {
//        calendar.reloadData()
        uiView.setCurrentPage(pageCurrent, animated: true) /// --->> replace calendar view when click on on left or proper button
        uiView.reloadData()
    }
class Coordinator: NSObject, FSCalendarDelegate, FSCalendarDataSource {
        
        var mother or father: CustomCalendar
        
        init(_ mother or father: CustomCalendar) {
            self.mother or father = mother or father
        }
 func setDataToCalender(ranges:[SelectionModel]) {
            mother or father.calendarModel.dateRanges = ranges
            mother or father.calendar.reloadData()
            for vary in ranges {
                setRangeToCalender(from: vary.startDate, to: vary.endDate)
            }
           
        }
 func calendar(_ calendar: FSCalendar, look: FSCalendarAppearance, fillSelectionColorFor date: Date) -> UIColor? {
            for vary in mother or father.calendarModel.dateRanges {
                if date >= vary.startDate && date <= vary.endDate {
                    return vary.colour
                }
            }
            
            return UIColor(Colour.theme.secondary)
        }
}

ineed answer for this

Leave a Reply

Your email address will not be published. Required fields are marked *