Selection color changes the events color in FSCalendar

非 Y 不嫁゛ 提交于 2019-12-02 18:29:49

问题


I have a project using FSCalendar in swift 4. I have events as green and red color. But while selecting the particular dates , the color of events changes to selection color. How can I solve this issue as given in image below. The event dots on the blue selection color must come either green or red.

For image you can see this link : https://github.com/WenchaoD/FSCalendar/issues/919


回答1:


I think you have not set the eventSelectionColor Property of FSCalendar.

You can set it programmatically by using below code.

calendar.appearance.eventSelectionColor = UIColor.green

or

You can set it from storyboard in Attributes inspector field.Set the event selection color property of FSCalendar as shown in below image.

Hope this will help you.




回答2:


For multiple event with different colors, you have to use FSCalendarDelegateAppearance method.

Example::::

//MARK: - set formatter of date

fileprivate let formatter: DateFormatter = {

        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd"
        return formatter }()

//MARK: - assign array of event

var arrayOfEvent1 : [String] = ["2018-08-14","2018-08-15"]

var arrayOfEvent2 : [String] = ["2018-08-14","2018-09-16"]



func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int 
{

     let strDate = self.formatter.string(from:date)

         if arrayOfEvent1.contains(strDate) && arrayOfEvent2.contains(strDate) 
         {
             return 2
         }
         else if arrayOfEvent1.contains(strDate)
         {
             return 1
         }
         else if arrayOfEvent2.contains(strDate)
         {
             return 1
         }

     return 0
}


func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance,eventDefaultColorsFor date: Date) -> [UIColor]?
{


    let strDate = formatter.string(from: date)

    if arrayOfEvent1.contains(strDate) && arrayOfEvent2.contains(strDate)
    {
        return [UIColor.red ,UIColor.blue]
    }
    else if arrayOfEvent1.contains(strDate)
    {
        return [UIColor.red]
    }
    else if arrayOfEvent2.contains(strDate)
    {
        return [UIColor.blue]
    }

    return [UIColor.clear]

}

func calendar(_ calendar: FSCalendar, appearance: FSCalendarAppearance, eventSelectionColorsFor date: Date) -> [UIColor]? {
      let strDate = formatter.string(from: date)

        if arrayOfEvent1.contains(strDate) && arrayOfEvent2.contains(strDate)                   
        {
            return [UIColor.red ,UIColor.blue]
        }
        else if arrayOfEvent1.contains(strDate)
        {
             return [UIColor.red]
        }
        else if arrayOfEvent2.contains(strDate)
        {
             return [UIColor.blue]
        }

            return [UIColor.clear]
    }

After execution of above delegate method we get two events on "2018-08-14".first event color is red and second event color is blue.

Hope this will help you.



来源:https://stackoverflow.com/questions/50020859/selection-color-changes-the-events-color-in-fscalendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!