Fscalendar: Custom row height for floating mode

Created on 21 Apr 2017  路  6Comments  路  Source: WenchaoD/FSCalendar

Currently the row height is dynamically calculated when not in floating mode. This allows for custom heights. But in floating mode, the row height is always 38pt. This is defined by the constant FSCalendarStandardRowHeight. Would be a good idea to add a public property to change this value?

All 6 comments

Try calendar.rowHeight = ....

@louisdh i have finished this. in floating mode, i do thiings as below.

  1. in FScalendar.m file, change the preferredRowHeight's setter method. just return the _rowHeight you want
- (CGFloat)preferredRowHeight
{
//    if (_preferredRowHeight == FSCalendarAutomaticDimension) {
//        CGFloat headerHeight = self.preferredHeaderHeight;
//        CGFloat weekdayHeight = self.preferredWeekdayHeight;
//        CGFloat contentHeight = self.transitionCoordinator.cachedMonthSize.height-headerHeight-weekdayHeight-_scopeHandle.fs_height;
//        CGFloat padding = 5;
//        if (!self.floatingMode) {
//            _preferredRowHeight = (contentHeight-padding*2)/6.0;
//        } else {
//            _preferredRowHeight = _rowHeight;
//        }
    }
    return _rowHeight;
}
  1. in FSCalendarCollectionViewLayout.m file, change the self.estimatedItemSize's configuration in [prepareLayout] method, just use calendar's rowHeight.
- (void)prepareLayout
{
   // ...
    self.estimatedItemSize = ({
        CGFloat width = (self.collectionView.fs_width-self.sectionInsets.left-self.sectionInsets.right)/7.0;
        CGFloat height = ({
            CGFloat height = FSCalendarStandardRowHeight;
//            if (!self.calendar.floatingMode) {
//                switch (self.calendar.transitionCoordinator.representingScope) {
//                    case FSCalendarScopeMonth: {
//                        height = (self.collectionView.fs_height-self.sectionInsets.top-self.sectionInsets.bottom)/6.0;
//                        break;
//                    }
//                    case FSCalendarScopeWeek: {
//                        height = (self.collectionView.fs_height-self.sectionInsets.top-self.sectionInsets.bottom);
//                        break;
//                    }
//                    default:
//                        break;
//                }
//            } else {
                height = self.calendar.rowHeight;
//            }
            height;
        });
        CGSize size = CGSizeMake(width, height);
        size;
    });
  // ...
}
  1. if you want to use the scope, from week to month or month to week, you should conform the protocol FSCalendarDelegate and configure calendar's frame in boundingRectWillChange method. just like this:
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
    NSLog(@"%@,bounds:%@",(calendar.scope==FSCalendarScopeWeek?@"week":@"month"),NSStringFromCGRect(bounds));
    // change frame
    CGRect calendarFrame = CGRectMake(0, calendar.nn_top, bounds.size.width, bounds.size.height);
    calendar.frame = calendarFrame;
    // others
}

  1. the last thing, use FSCalendar's intitWithFrame method, set the property rowHeight of FSCalendar class.
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, kIsIPhoneX ? 88 : 64 , self.view.nn_width, 44 + 20 + 4 + 54 * 6)];
calendar.rowHeight = 54;
 // ...

anyone just have a try, and good luck.

Can I just double check what floating mode is?

My issue was the height when in week mode, as in the calendar would need to be full height etc.

did you mean the row height is equal to calendar' height when in week mode?鍙戣嚜鎴戠殑iPhone------------------ Original ------------------From: Jules2010 notifications@github.comDate: Sat,Sep 1,2018 6:23 PMTo: WenchaoD/FSCalendar FSCalendar@noreply.github.comCc: george-luofz george_luofz@163.com, Comment comment@noreply.github.comSubject: Re: [WenchaoD/FSCalendar] Custom row height for floating mode (#655)Can I just double check what floating mode is?
My issue was the height when in week mode, as in the calendar would need to be full height etc.

鈥擸ou are receiving this because you commented.Reply to this email directly, view it on GitHub, or mute the thread.
{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/WenchaoD/FSCalendar","title":"WenchaoD/FSCalendar","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/WenchaoD/FSCalendar"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Jules2010 in #655: Can I just double check what floating mode is?\r\n\r\nMy issue was the height when in week mode, as in the calendar would need to be full height etc."}],"action":{"name":"View Issue","url":"https://github.com/WenchaoD/FSCalendar/issues/655#issuecomment-417848852"}}}
[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/WenchaoD/FSCalendar/issues/655#issuecomment-417848852",
"url": "https://github.com/WenchaoD/FSCalendar/issues/655#issuecomment-417848852",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [WenchaoD/FSCalendar] Custom row height for floating mode (#655)",
"sections": [
{
"text": "",
"activityTitle": "Jules2010",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@Jules2010",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"WenchaoD/FSCalendar\",\n\"issueId\": 655,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/WenchaoD/FSCalendar/issues/655#issuecomment-417848852"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 219163885\n}"
}
],
"themeColor": "26292E"
}
]

No it鈥檚 totally messed up, although I think it鈥檚 due to another option I鈥檓 also using. The option with next and previous month / week in the top left / right turned off I think.

You have to have a descent height or it squashed things at an optional height.

@Jules2010
how many descent height did you have?
there is a sectionInsets in the FSCalendarCollectionViewLayout, its default value is (5,0,5,0). maybe you can change it to (0,0,0,0).

Was this page helpful?
0 / 5 - 0 ratings