【发布时间】:2018-04-10 10:31:02
【问题描述】:
我想为我的应用开发自定义 calendarView。我想我可以像这样使用UICollectionView 来实现:
我尝试了这个简单的事情:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 5 //for number of weeks
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 7 //for number of days in week
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AvailabilityCollectionViewCell", for: indexPath) as! AvailabilityCollectionViewCell
cell.lblDate.text = "\(indexPath.row)"
cell.layer.borderColor = UIColor.black.cgColor
cell.layer.borderWidth = 0.5
return cell
}
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat{
return 0.0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.size.width / 7.0, height: collectionView.frame.size.height / 5)
}
通过这个我得到这样的简单集合视图:
现在我想知道如何根据日历安排工作日以及这需要什么样的数据源...
谢谢..
【问题讨论】:
-
你可以使用这个日历github.com/WenchaoD/FSCalendar
-
您想使用日历组件来获取每月第一天的“星期几”,然后从该偏移量开始填充您的网格。请参阅 Apple 的 Date and Time Programming Guide ... 以及此处的基本示例:stackoverflow.com/a/25533357/6257435
标签: ios swift uicollectionview calendarview