New to Telerik UI for Xamarin? Download free 30-day trial

Custom Accessibility Label for iOS calendar

Environment

Product Version 2021.1.325.1
Product Calendar for Xamarin Cross-Platform

Description

This article will show you how to access the default accessibility label on iOS calendar for MonthView

Solution

  1. Create a custom renderer and create custom delegate:
public class CustomCalendarRenderer : CalendarRenderer
{
    protected override CalendarDelegate CreateCalendarDelegateOverride()
    {
        return new CustomCalendarDelegate();
    }
}
  1. The CustomCalendarDelegate implementation. You will need to create a custom cell:
public class CustomCalendarDelegate : CalendarDelegate
{
    public override TKCalendarCell ViewForCellOfKind(TKCalendar calendar, TKCalendarCellType cellType)
    {
        if (cellType == TKCalendarCellType.Day)
        {
            CustomCell cell = new CustomCell();
            return cell;
        }
        return base.ViewForCellOfKind(calendar, cellType);
    }
}
  1. CustomCell implementation. override the AttachWithCalendar method inside the CustomCell, call the base, then implement custom logic to get the information from the events. Then set this information to the AccessibilityLabel.
public class CustomCell : TKCalendarDayCell
{
    public override void AttachWithCalendar(TKCalendar owner, NSDate date)
    {
        base.AttachWithCalendar(owner, date);

        // Here you can override the default AccessibilityLabel
        if (this.Events != null)
        {
            StringBuilder builder = new StringBuilder();
            foreach (var app in this.Events)
            {
                builder.AppendLine(string.Format("{0} {1}", app.GetTitle(), app.GetEventColor().ToString()));
            }

            this.AccessibilityLabel = builder.ToString();
        }
    }
}
In this article
Not finding the help you need? Improve this article