3

How do I configure FSCalendar to support RTL language numerals ?

Here's the code I'm using

FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 300, 320)];
calendar.dataSource = self;
calendar.delegate = self;
calendar.backgroundColor = [UIColor whiteColor];
calendar.appearance.headerMinimumDissolvedAlpha = 0;
calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase;
calendar.scrollDirection = FSCalendarScrollDirectionHorizontal;
calendar.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ar_AE"];

When I launch the calendar view, I cannot get the dates to display using the correct language numerals

enter image description here As you can see only partial content is displayed correctly. I'm on iOS 10.

@WenchaoD Any thoughts on how to get this to work ?

ArdenDev
  • 4,051
  • 5
  • 29
  • 50
  • FSCalendar doesn't support the RTL mode, please check this pod: https://github.com/MosheBerman/MBCalendarKit – Maor Aug 28 '17 at 15:22
  • Does not support RTL. Try using [This one](https://github.com/patchthecode/JTAppleCalendar). Full tutorials found [Here](https://www.youtube.com/watch?v=wyh_DVFeH_w&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q) – swift nub Sep 16 '17 at 03:11

1 Answers1

1

Complete RTL is not possible in FSCalendar, we can add arabic numerals to the calendar.

Here is my solution, it solved my issue hope it will satisfy your requirement.

In this solution i used the possibility of title option in FSCAlendar.By doing this users with arabic tongue can easily use the calendar.

func showArabicSubTitle(date: Date!) -> String!
{

    let dateFormater = DateFormatter()
    dateFormater.dateFormat = "dd"

    var calendarDate = dateFormater.string(from: date as Date)

    let characters = Array(calendarDate.characters)

    let substituteArabic = ["0":"٠", "1":"١", "2":"٢", "3":"٣", "4":"٤", "5":"٥", "6":"٦", "7":"٧", "8":"٨", "9":"٩"]
    var arabicDate =  ""

    for i in characters {
        if let subs = substituteArabic[String(i)] {
            arabicDate += subs
        } else {
            arabicDate += String(i)
        }
    }

    return arabicDate
}

//MARK: - FSCalendarDelegate

func calendar(_ calendar: FSCalendar, titleFor date: Date) -> String? {
    return (L102Language.currentAppleLanguage() == "ar") ? self.showArabicSubTitle(date: date) : ""
}
Rahul K Rajan
  • 776
  • 10
  • 19