Category / Section
How to customize the specific date cell in month view of Xamarin.iOS Calendar (SfCalendar)
1 min read
You can customize the month cell using the DrawMonthCell event of SfCalendar in Xamarin. iOS
C#
Using the DrawMonthCell event, you can use the View property from DrawMonthCellEventArgs to customize a specific month cell.
private void CalendarDrawMonthCell(object sender, DrawMonthCellEventArgs e) { NSCalendar date = NSCalendar.CurrentCalendar; NSDate today = new NSDate(); NSDateComponents monthCellDateComponents = date.Components( NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, e.MonthCell.Date); NSDateComponents todayDateComponents = date.Components( NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today); UIButton button = new UIButton(); button.SetTitle(monthCellDateComponents.Day.ToString(), UIControlState.Normal); button.SetTitleColor(UIColor.Black, UIControlState.Normal); if (e.MonthCell.IsCurrentMonth) { if (monthCellDateComponents.Day == todayDateComponents.Day && monthCellDateComponents.Month == todayDateComponents.Month && monthCellDateComponents.Year == todayDateComponents.Year) { //// customized particular date by setting different background color button.BackgroundColor = UIColor.Red; } else { button.BackgroundColor = UIColor.LightGray; } e.MonthCell.View = button; } }