xamarin-forms-docs/knowledge-base/calendar-remove-appointment...

2.3 KiB

title description type page_title slug position tags ticketid res_type
Remove background color from calendar appointment how to remove the appointment background color for day view how-to remove appointment background color in day view calendar-remove-appointment-background-color calendar, appointment, color, dayview, xamarin, ios 1513099 kb

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;
        }
    }
}