Current date border color is displayed multiple times in JTCalendar in Swift

160 Views Asked by At

I am displaying booked dates in grey cell background and the current date in a black border color. I have an issue that the border color that is used to display the current day appears after every three months at the same spot. Kindly how may i solve this? I have tried to look up questions on this issue. I think i have just miss matched my statements. If anyone can see what wrong am doing kindly help me fix this.

enter image description here enter image description here

public func calendar(_ calendar: JTCalendarManager!, prepareDayView dayView: (UIView & JTCalendarDay)!)
{
    let mydayview=dayView as! JTCalendarDayView

if dayView.isFromAnotherMonth(){
        dayView.isHidden = true


    }
    //        compareWithCurrentDate(date: mydayview.date)

    mydayview.textLabel.font = UIFont(name:"Montserrat-Regular", size:13)
    mydayview.circleRatio = 2
        //1.5
// cornerradius
    mydayview.circleView.layer.cornerRadius = 1

    mydayview.isFromAnotherMonth = false

    mydayview.textLabel.textColor = UIColor.gray


    let dateFormatter = DateFormatter()
    dateFormatter.locale = Locale(identifier: "en_US_POSIX")
    dateFormatter.dateFormat = "yyyy-MM-dd"

    let dateStr = dateFormatter.string(from: mydayview.date)
    print(dateStr)

    if(isAVailableOnSelectedDate(dateStr: dateStr)){

        let now = Date()
        dateFormatter.dateFormat = "yyyy-MM-dd"

        print(dateFormatter.string(from: now))

        if  let currentDate = calendarManager.date() {

         let currentDateString = String(describing: currentDate)

            print(currentDateString)

            if  dateFormatter.string(from: now) == currentDateString.prefix(10){

                mydayview.circleView.isHidden = false

              mydayview.circleView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.5)
                         //1

                mydayview.backgroundColor = UIColor.white
                mydayview.textLabel.textColor = UIColor.black


            }


            else{

                mydayview.circleView.isHidden = true;
                mydayview.backgroundColor = UIColor.white
                           // mydayview.dotView.backgroundColor = UIColor.red
                mydayview.textLabel.textColor = UIColor.gray


            }




        }

    }
    else if calendarManager.dateHelper.date(calendarContentView.date, isTheSameMonthThan: mydayview.date)
    {
        mydayview.circleView.isHidden = true;
        mydayview.backgroundColor = UIColor.white
        // mydayview.dotView.backgroundColor = UIColor.red
        mydayview.textLabel.textColor = UIColor.gray
    }
        // Another day of the current month
    else
    {
        mydayview.circleView.isHidden = true;
        mydayview.backgroundColor = UIColor.white
        mydayview.dotView.backgroundColor = UIColor.clear
        mydayview.textLabel.textColor = UIColor.lightGray
        // mydayview.textLabel.textColor = UIColor.clear
    }

    //Current day

    if calendarManager.dateHelper.date(Date(), isTheSameDayThan: mydayview.date) {

        mydayview.circleView.isHidden = false
        mydayview.circleView.backgroundColor = UIColor.white
        mydayview.layer.borderColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
        mydayview.layer.borderWidth = 1

    }
    else if mydayview.date > Date(){
       // mydayview.layer.borderColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        mydayview.circleView.isHidden = true;
                   mydayview.backgroundColor = UIColor.white
                   mydayview.dotView.backgroundColor = UIColor.clear
                   mydayview.textLabel.textColor = UIColor.lightGray
    }

}
0

There are 0 best solutions below