簡體   English   中英

FSCalendar的scope月周變化時如何動態改變單元格大小?

[英]How to dynamically change cell size when scope of FSCalendar changes from month to week?

當我每周更改我的 FSCalendar scope 時,我一直在嘗試更改 tableview 單元格大小,反之亦然。 這在calender.scope =.week上工作正常,內容按要求正確顯示,但日歷的邊界沒有更新,因此我的單元格大小不會改變它的高度。

當我更改我的 scope 並重新加載日歷時,我確實按照我的目標實現了。

func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
    self.calenderView.frame.size.height = bounds.height
}

我的日歷視圖在 tableview 單元格中退出,當日歷更改為 scope 時,單元格大小也應該更改,但現在它不起作用。

請幫我。

試試這個代碼

var height: CGFloat?

func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
    self.height = bounds.height
    self.calenderView.frame.size.height = bounds.height
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    // Here you can return specify the height of the cell.
    return height
}

這樣做的目的是為 tableviewcell 和 calenderview 設置相同的高度。 如果你想在水平軸上有多個單元格,那么考慮使用 collectionview。

因此我們不必指定 tableVieCell 的寬度。

我們所做的是在 class 中存儲一個可選的高度值,然后在調用 boundingRectWillChange 方法時設置它。

希望這個回答對你有幫助,如果有問題請告訴我!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM