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

Remove background color from calendar appointment

Environment

Product Version 2021.1.119.1
Product Calendar for Xamarin Cross-Platform

Description

This help article will show you how to remove the Calendar appointment background color on iOS for day view mode. For the purpose we will need to use a custom renderer for iOS.

Solution

Create a class inside the iOS project CustomCalendarRenderer which inherits from CalendarRenderer and override the CreateCalendarDayViewDataSource. Then return new CustomCalendarDayViewDataSource. Inside this class override the EventCellForItemAtIndexPath method and set Transparency to the cell style:

using App1.iOS;
using Foundation;
using Telerik.XamarinForms.Input;
using Telerik.XamarinForms.InputRenderer.iOS;
using TelerikUI;
using UIKit;
using Xamarin.Forms;

[assembly: ExportRenderer(typeof(RadCalendar), typeof(CustomCalendarRenderer))]
namespace App1.iOS
{
    public class CustomCalendarRenderer : CalendarRenderer
    {
        protected override CalendarDayViewDataSource CreateCalendarDayViewDataSource()
        {
            return new CustomCalendarDayViewDataSource(this);
        }
    }



    internal class CustomCalendarDayViewDataSource : CalendarDayViewDataSource
    {
        public CustomCalendarDayViewDataSource(CalendarRenderer renderer)
            : base(renderer)
        {
        }

        public override UICollectionViewCell EventCellForItemAtIndexPath(TKCalendarDayView dayView, NSIndexPath indexPath)
        {
            var cell = base.EventCellForItemAtIndexPath(dayView, indexPath);
            if (cell is TKCalendarDayViewEventCell eventCell)
            {
                eventCell.Style.Transparency = 0.0f;
            }

            return cell;
        }
    }
}
In this article