我想在我的应用程序中的iOS上创建一个新的自定义日历。
我寻找一些有关其工作原理的说明。但是我的代码不起作用/未创建日历
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
if (source.sourceType == EKSourceTypeLocal) {
theSource = source;
break;
}
}
NSString *identifier;
EKCalendar *cal;
if (identifier == nil)
{
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:eventStore];
cal.title = @"MyCustomCalendar";
cal.source = theSource;
[eventStore saveCalendar:cal commit:YES error:nil];
NSLog(@"cal id = %@", cal.calendarIdentifier);
}
else
{
cal = [eventStore calendarWithIdentifier:identifier];
}
最佳答案
我不确定您是否已完全设置使用EKCalendar,但无需在iOS中创建日历。您可以根据需要设计自己的UICollectionView或动态布局的Button。重要的是要确保正确安排所有日期,这不一定很琐碎。但是,如果您有一个很好的方法来获取给定月份的第一天的第一个工作日,则可以完成该工作。我遵循了以下算法:http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week似乎有点复杂,但实际上易于编写且可靠。否则,我认为苹果可以尝试使用“firstWeekday”方法/属性,但这对我不起作用。有了合适的第一个工作日后,您就可以枚举该月剩余时间的日期,并将它们放在日历上。
似乎您不确定如何使用EKCalendar设置日历数据。我发现了一个不错的教程,您可能会觉得有用:
http://oleb.net/blog/2012/05/creating-and-deleting-calendars-in-ios/
对于更具体的问题,请尝试使用该文档,您可以通过Google搜索找到它。
否则,您要寻找哪种数据导出? iCloud?本地?您是在使用提供的实际日历,还是只是将其与其他应用程序可以读取的所有日历数据一起保存?
关于ios - 创建自定义日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27398924/