1

I am developing an app with custom calendar.It includes day view with list of events of that day.I am getting the array of events with overlapped time slots. Now how can I display the events with proper block adjustment?

I can find the overlapped events group,But not able to set the block adjustment. Ex:- I have below events

1)From 8:00 To 12:00 event A

2)From 8:00 To 9:00 event B

3)From 9:00 To 10:00 event C

4)From 10:00 To 11:00 event D

5)From 11:00 To 12:00 event E

should be display like below picture.enter image description here This is only one type of case,I have many other type of combination. To draw the Rect I used below method. *- (void)drawRect:(CGRect)rect { [super drawRect:rect];

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetRGBFillColor(context, 244.0/255.0, 244.0/255.0, 244.0/255.0, 1.0);

for (int i=0; i<arrayRects.count; i++)
{
    if ([[arrayRects objectAtIndex:i] isKindOfClass:[NSMutableArray class]])
    {
        NSMutableArray *confictArray =(NSMutableArray*)[arrayRects objectAtIndex:i];

        for (int j=0; j<confictArray.count; j++)
        {
            NSString *strRect = [confictArray objectAtIndex:j];
            CGRect newRect = CGRectFromString(strRect);
            newRect.size.height -=1.5;
            CGContextFillRect(context, newRect);

            //Draw Line on Left
            {
                if(i==0) {
                    CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0); // green line
                } else if(i==1) {
                    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); // red line
                } else {
                    CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0); // blue line
                }

                CGContextBeginPath(context);

                CGContextMoveToPoint(context, newRect.origin.x , newRect.origin.y + 0.5); //start point
                CGContextAddLineToPoint(context, newRect.origin.x ,newRect.origin.y + newRect.size.height - 0.5); // end path

                CGContextClosePath(context); // close path

                CGContextSetLineWidth(context, 5.0); // this is set from now on until you explicitly change it
                CGContextStrokePath(context); //
            }
        }
    }
    else {

        NSString *strRect = [arrayRects objectAtIndex:i];
        CGRect newRect = CGRectFromString(strRect);
        newRect.size.height -=1.5;
        CGContextFillRect(context, newRect);

        //Draw Line on Left
        {
            if(i==0) {
                CGContextSetRGBStrokeColor(context, 0.0, 1.0, 0.0, 1.0); // green line
            } else if(i==1) {
                CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); // red line
            } else {
                CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0); // blue line
            }

            CGContextBeginPath(context);

            CGContextMoveToPoint(context, newRect.origin.x , newRect.origin.y + 0.5); //start point
            CGContextAddLineToPoint(context, newRect.origin.x ,newRect.origin.y + newRect.size.height - 0.5); // end path

            CGContextClosePath(context); // close path

            CGContextSetLineWidth(context, 5.0); // this is set from now on until you explicitly change it
            CGContextStrokePath(context); //
        }
    }
}*
Vivek Shah
  • 430
  • 5
  • 22
  • show your implemented code. – Dheeraj Singh Feb 23 '15 at 13:14
  • I got the event time slots from the Database.After that I grouped that events according to below link. http://stackoverflow.com/questions/10578730/algorithm-for-finding-overlapping-events-times So in our case I get 1 group of events,but I can't figure out how to display it. – Vivek Shah Feb 23 '15 at 13:18
  • i got u what u wanna need but show your code to help u. where u are inserting events in your custom calendar. – Dheeraj Singh Feb 23 '15 at 13:23
  • I want to create something like this http://postimg.org/image/fk5fajms7/ To draw the Rect I used CGContextFillRect(context, newRect); and the background "time with AM-PM" and lines are drawn in scrollview – Vivek Shah Feb 23 '15 at 13:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71552/discussion-between-vivek-shah-and-dheeraj-singh). – Vivek Shah Feb 24 '15 at 06:34

0 Answers0