Nou*_*man 3 calendar ios swift jtapplecalendar
我在 iOS 应用程序中使用 JTAppleCalendar,但我发现很难实现像传统日历通常那样在日历顶部显示月份和年份的标题。我已按照文档中的说明进行操作,但尽管我设法添加“标题”来显示一周中的几天,但我仍然发现这很困难,尽管我觉得可能不正确。对于以前实现过这个库的人来说,我可以获得一些如何做到这一点的帮助吗?或者也许您使用过的另一个日历有更简单的方法来完成此任务?
文档: https: //patchthecode.github.io/Headers/
我这样实现一周中的几天:
// This sets the height of your header
func calendar(_ calendar: JTAppleCalendarView, sectionHeaderSizeFor range: (start: Date, end: Date), belongingTo month: Int) -> CGSize {
return CGSize(width: 200, height: 50)
}
// This setups the display of your header
func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) {
let headerCell = (header as? PinkSectionHeaderView)
headerCell?.title.text = "S M T W T F S"
}
Run Code Online (Sandbox Code Playgroud)
我认为你只是让这件事变得比应有的困难得多。
您在教程网站上看到的是一个示例,说明如何使用名为 的简单 UILabel 设置标题title。如果您的日历设计不同,则不必严格遵循这一点。只需按照您的意愿设计即可。
看来你想要的不是 UILabel。你想要 7 个标签;每个代表一周中的一天。最简单的方法就是在 Horizontal Stackiew 中创建 7 个 UILabel。StackView 的间距应设置为full且应设置为fill equally。然后您所要做的就是单击各个标签并将其对齐方式设置为居中。
使 StackView 的约束延伸到 headerView 的两端。完毕。您的 S|M|T|W|T|F|S 视图是完整的,无需对空格进行硬编码;这是一件坏事。
接下来,您似乎还想要另外 2 个标签。一个为Month,另一个为Year。因此,在标题视图中创建这些标签,然后为它们创建outletLets。然后你可以在下面的函数中正确设置它们。
func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2842 次 |
| 最近记录: |