Configuring a Custom Appointment Color
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview of configuring custom appointment color on the IGCalendarView™ control and demonstrates the configuration using a code example.

In this topic


Introduction

Custom appointment color summary

IGCalendarAppointment objects by default get their appointment color from the data source, but it is also possible to dynamically color each appointment by setting the color property. The best time to set this property is during the creation of the IGCalendarAppointment object in one of the following IGCalendarAppointmentDataSource methods.

  • calendarView:appointmentsForStart:end:ofType:
  • calendarView:asyncAppointmentRequest:ofType:

To learn more about creating appointments refer to the Configuring Appointments topic.


Configuring a Custom Appointment Color – Code Example

Description

The code example below demonstrates changing an appointments color on the IGCalendarView from the calendarView:appointmentsForStart:end:ofType: method when adopting the IGCalendarAppointmentDataSource protocol.

Preview

Prerequisites

This code example requires the inclusion of the IG framework; details about how to add this framework are available in the Adding the IG Framework File topic.

Code

In Objective-C:

- (NSArray *)calendarView:(IGCalendarView *)calView appointmentsForStart:(NSDate *)start end:(NSDate *)end ofType:(IGCalendarAppointmentRequestType)requestType
{
    NSTimeInterval min = [start timeIntervalSince1970];
    NSTimeInterval max = [end timeIntervalSince1970];
    NSMutableArray *returnAppts = [[NSMutableArray alloc] init];
    for (NSDictionary *appt in _appts)
    {
        NSDate *startTime = appt[@"start"];
        NSTimeInterval current = [startTime timeIntervalSince1970];
        if (current >= min && current <= max)
        {
            IGCalendarAppointment *calAppt = [[IGCalendarAppointment alloc] init];
            calAppt.startTime = startTime;
            calAppt.endTime = appt[@"end"];
            calAppt.location = appt[@"location"];
            calAppt.title = appt[@"title"];
            calAppt.color = [UIColor colorWithRed:arc4random_uniform(256) / 255.0f
                                            green:arc4random_uniform(256) / 255.0f
                                             blue:arc4random_uniform(256) / 255.0f
                                            alpha:1];
            [returnAppts addObject:calAppt];
        }
    }
    return returnAppts;
}

In C#:

public override NSObject[] GetAppointments (IGCalendarView calView, NSDate start, NSDate end, IGCalendarAppointmentRequestType requestType)

{

Double min = start.SecondsSinceReferenceDate;

Double max = end.SecondsSinceReferenceDate;

List<IGCalendarAppointment> returnAppts = new List<IGCalendarAppointment>();

foreach (NSDictionary appt in _appts) {

NSDate startTime = appt ["start"];

Double current = startTime.SecondsSinceReferenceDate;

if (current >= min && current <= max) {

IGCalendarAppointment calAppt = new IGCalendarAppointment ();

calAppt.StartTime = startTime;

calAppt.EndTime = appt ["end"];

calAppt.Location = appt ["location"];

calAppt.Title = appt ["title"];

calAppt.Color = new UIColor (new Random ().Next (255) / 255.0f, new Random ().Next (255) / 255.0f, new Random ().Next (255) / 255.0f, 1.0f);

returnAppts.Add (calAppt);

}

}

return returnAppts;

}


Related Content

Topics

The following topic provides additional information related to this topic.

Topic

Purpose

The topics in this group cover enabling, configuring, and using the IGCalendarView control’s supported features.