Fscalendar: Adjust Month View Width

Created on 15 Feb 2019  Â·  4Comments  Â·  Source: WenchaoD/FSCalendar

HI,
How can I make the monthview width bigger?

I add another UILabel to the month view(FSCalendarHeaderCell) but i can't find a way to make its total width bigger. There's an option to adjust its height but not width

Thanks

Most helpful comment

@chamroeunbm
You can change FSCalendarHeaderCell width by implementing this code:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    changeMonthName()
}

func changeMonthName(){
    let collectionView = self.calendar.calendarHeaderView.value(forKey: "collectionView") as! UICollectionView

    collectionView.visibleCells.forEach { (cell) in
    let c = cell as! FSCalendarHeaderCell

    var frame = c.frame
    frame.size.width = 250
    c.frame = frame

    c.setNeedsLayout()
    }
}

// MARK:- FSCalendarDelegate

func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
    changeMonthName()
}

All 4 comments

@chamroeunbm
You can change FSCalendarHeaderCell width by implementing this code:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    changeMonthName()
}

func changeMonthName(){
    let collectionView = self.calendar.calendarHeaderView.value(forKey: "collectionView") as! UICollectionView

    collectionView.visibleCells.forEach { (cell) in
    let c = cell as! FSCalendarHeaderCell

    var frame = c.frame
    frame.size.width = 250
    c.frame = frame

    c.setNeedsLayout()
    }
}

// MARK:- FSCalendarDelegate

func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
    changeMonthName()
}

thanks

HI, this create a messy view after swiping a few month.

There're 3 visible cells. I try to change size of the second cells(current month) and deduct size of the previous month and next month, but this also doesn't work.

i think we need some more tweak to get it working properly.

Hi, this solution doesn't work. After scrolling a few month, all the month name corrupted and overlap each other

Was this page helpful?
0 / 5 - 0 ratings