问题描述
CollectionView我尝试使用“ calendar.collectionView.fs_height = 60”之类的不同方法来修改CollectionView的高度,但是没有任何效果。 CollectionView的高度由一个函数计算。因此,我试图禁用此功能或仅能够修改高度。谢谢!
这是代码
导入UIKit 进口FSCalendar 导入SnapKit
ViewController类:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let calendar = FSCalendar(frame: CGRect(x: 0,y: 0,width: view.frame.width,height: 224))
calendar.weekdayHeight = 30
calendar.dataSource = self
calendar.delegate = self
calendar.scope = .week
calendar.register(FSCalendarCell.self,forCellReuseIdentifier: "Cell")
view.addSubview(calendar)
}
func calendar(_ calendar: FSCalendar,boundingRectWillChange bounds: CGRect,animated: Bool) {
calendar.snp.updateConstraints { (make) in
make.height.equalTo(bounds.height)
make.top.equalTo(40)
}
self.view.layoutIfNeeded()
}
}
扩展ViewController:FSCalendarDelegate,FSCalendarDataSource {
func calendar(_ calendar: FSCalendar,cellFor date: Date,at position: FSCalendarMonthPosition) -> FSCalendarCell {
let cell = calendar.dequeueReusableCell(withIdentifier: "Cell",for: date,at: position)
cell.fs_height = 35
return cell
}
}
解决方法
请将代码粘贴到尝试执行此操作的地方。
collectionView的大小由您为其设置的框架的大小(不是推荐者)定义,或者由布局上的约束条件决定。
您的问题似乎记录在FSCalendar存储库页面中,
FSCalendar不会自行更新框架,请实施
检查您要使用哪种系统进行布局,并实施
boundingRectWillChange