Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:36:53+00:00 2026-05-31T14:36:53+00:00

I am making a day view calendar just like the native iPhone calendar. I

  • 0

I am making a day view calendar just like the native iPhone calendar. I am trying to position the tiles the same as in the native calendar, side by side, if they are the same size and same time.

However, I can only figure out how to do it to 2 tiles and not multiple tiles. In the attached image I have 4 tiles. One that expands slightly into the other 3. I then have the first tile on the far left and the second tile just after the first one. Now I need to figure out how to add the additional tiles?

How would I do this for more than 2 tiles?

About the image: If you can’t see it the 3rd tile is ontop of the 2nd tile (you can see it is a bit darker since they are on top of each other.

screenshot

- (void)layoutSubviews
{
    // Set the main
    for (UIView *view in self.subviews) {
        APCalendarDayTile *tile = (APCalendarDayTile *)view;
        CGFloat startPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.startDate]];
        CGFloat endPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.endDate]];
        tile.frame = CGRectMake(kLeftSideBuffer, startPos, (self.bounds.size.width - kLeftSideBuffer) , endPos - startPos);
        tile.backgroundColor = [UIColor colorWithHexString:tile.appointment.appointmentColor];
    }

    for (UIView *view in self.subviews) {
        APCalendarDayTile *tile = (APCalendarDayTile *)view;

        if ([self viewIntersectsWithAnotherView:tile]) {

        }
    }
}

- (BOOL)viewIntersectsWithAnotherView:(UIView*)selectedView{
    NSArray *subViewsInView=[self subviews];// I assume self is a subclass
    // of UIViewController but the view can be
    //any UIView that'd act as a container 
    //for all other views.
    for (UIView *theView in subViewsInView){
        if (![selectedView isEqual:theView]) {
            if(CGRectIntersectsRect(selectedView.frame, theView.frame)) {
                if ((selectedView.frame.origin.y == theView.frame.origin.y) && (selectedView.frame.size.height == theView.frame.size.height)) {
                    if (theView.frame.size.width == self.bounds.size.width - kLeftSideBuffer) {
                        theView.frame = CGRectMake(theView.frame.origin.x, selectedView.frame.origin.y, theView.frame.size.width / 2, selectedView.frame.size.height);
                    }
                    selectedView.frame = CGRectMake(theView.frame.origin.x + theView.frame.size.width, selectedView.frame.origin.y, theView.frame.size.width, selectedView.frame.size.height);
                    return YES;
                }
            }
        }
    }
    return NO;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:36:58+00:00Added an answer on May 31, 2026 at 2:36 pm

    Ok,

    I sorta took SaltyMule’s approach however, his pseudo code didn’t make sense in the if / else.

    - (void)layoutSubviews
    {
        // Set the main
        for (UIView *view in self.subviews) {
            APCalendarDayTile *tile = (APCalendarDayTile *)view;
            CGFloat startPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.startDate]];
            CGFloat endPos = [APCalendarCurrentDayView yAxisForTime:[APCalendarCurrentDayView minutesToTime:tile.appointment.endDate]];
            tile.frame = CGRectMake(kLeftSideBuffer, startPos, (self.bounds.size.width - kLeftSideBuffer) , endPos - startPos);
            tile.backgroundColor = [UIColor colorWithHexString:tile.appointment.appointmentColor];
        }
    
        [sameTimeAppointments removeAllObjects];
    
        for (UIView *view in self.subviews) {
            APCalendarDayTile *tile = (APCalendarDayTile *)view;
    
            if ([self viewIntersectsWithAnotherView:tile]) {
                if ([sameTimeAppointments objectForKey:[NSString stringWithFormat:@"%f", tile.frame.origin.y]] != nil) {
                    NSMutableArray *tempArray = [[sameTimeAppointments objectForKey:[NSString stringWithFormat:@"%f", tile.frame.origin.y]] mutableCopy];
                    [tempArray addObject:tile];
                    [sameTimeAppointments setValue:tempArray forKey:[NSString stringWithFormat:@"%f", tile.frame.origin.y]];
                } else {
                    [sameTimeAppointments setValue:[NSMutableArray arrayWithObject:tile] forKey:[NSString stringWithFormat:@"%f", tile.frame.origin.y]];
                }
            }
        }
        for (NSString *currentDict in sameTimeAppointments) {
            NSArray *currentAppointments = [sameTimeAppointments objectForKey:currentDict];
            float tileWidth = ((self.frame.size.width - kLeftSideBuffer) / [currentAppointments count]);
            for (int i = 0; i < [currentAppointments count]; i++) {
                APCalendarDayTile *tile = [currentAppointments objectAtIndex:i];
                float xPos = 0.0 + kLeftSideBuffer;
                if (i != 0) {
                    xPos = (((APCalendarDayTile *)[currentAppointments objectAtIndex:i - 1]).frame.origin.x + tileWidth);
                }
    
                tile.frame = CGRectMake(xPos, tile.frame.origin.y, tileWidth, tile.frame.size.height);
                [self bringSubviewToFront:tile];
            }
        }
    }
    
    - (BOOL)viewIntersectsWithAnotherView:(UIView*)selectedView{
        NSArray *subViewsInView=[self subviews];// I assume self is a subclass
        // of UIViewController but the view can be
        //any UIView that'd act as a container 
        //for all other views.
        for (UIView *theView in subViewsInView){
            if (![selectedView isEqual:theView]) {
                if(CGRectIntersectsRect(selectedView.frame, theView.frame)) {
                    if ((selectedView.frame.origin.y == theView.frame.origin.y) && (selectedView.frame.size.height == theView.frame.size.height)) {
                        return YES;
                    }
                }
            }
        }
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android app that shows the Calendar day view, it looks
I have just spent half a day quietly going mad. I'm making changes to
I'm making my custom calendar view for an app for the European market. In
I am making reduce view for counting users notes for date range and I
I am making a web page which will allow users to input and view
I was playing around the other day with making a class to handle some
I am trying to make a calendar on my website. So in my C#
I am trying to implement Tab View for my activity. I am getting an
these day im making python script related with DOM. problem is these day many
these day im making some web crawler script, but one of problem is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.