objective-c - 如何以编程方式在日历中以与月份和星期相匹配的方式布局日期?

标签 objective-c uitableview uicollectionview

我该怎么做?

我确定以前已经这样做过。我在github上检查了几个项目,例如calendar master,但它们都比我需要的更复杂。

2013 年 10 月

SM T W T F S

30 1 2 3 4 5 6

7 8 9 10 11 12 13

14 15 16 17 18 19 20

21 22 23 24 25 26 27

28 29 30 311 2 3

有没有最好的方法来做到这一点?要以与该月的星期几相匹配的方式布局日期?

这将在表格 View 中进行,但我不是在寻找代码,只是在寻找其背后的逻辑。除非已经有一个非常好的解决方案。

谢谢!

最佳答案

逻辑可能是这样的(伪代码):

get the weekday of the first day of the month in question
determine the number of days of the previous month
fill the first line 
   with leading final days of previous month, if any
   the remaining days for the first week of the month in question
fill all other lines
fill the rest of the last line 
   with the first days of the following month, if any space left

关于objective-c - 如何以编程方式在日历中以与月份和星期相匹配的方式布局日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19347364/

相关文章:

iphone - 在 Objective C 中写入 TCP 套接字时出现问题(错误消息)

objective-c - 当用于@property 时,属性(弱)意味着什么?

ios - 当滚动 tableView 达到阈值时在 TableView 上显示文本

swift - 我的自定义 UICollectionViewCell 中的图像没有扩展到单元格的整个边界?

ios - 删除核心数据中的对象

objective-c - 在 UIWebView 中显示网页

ios - DidSelectRow 方法由于 tapGestureRecognizer 而被禁用

iphone - 通过选择 UITableView 行调用新 View 错误

iphone - iOS 子类 UICollectionViewCell 自定义初始化方法

swift - 在 1 个 View Controller 中显示图像到 2 个 Collection View