如何更改 FSCalendar 上的 Header 查看标题字体并添加副标题?

How can you change the Header View title font on FSCalendar and add a Subtitle?

I am trying to set the header title font to a much larger style font more like a big banner, and set a subtitle underneath it of the year.

extension FSCalendar {
func customizeCalendar() {
    appearance.caseOptions = [.headerUsesUpperCase]
    appearance.headerDateFormat = "MMM"
    headerHeight = 100
    
    let header = FSCalendarHeaderView()
    header.largeContentTitle?.append("aldjsf")
   
    
    appearance.headerTitleFont = UIFont(name: "SFProDisplay-Bold", size: 200)
    appearance.headerTitleColor = COLOR_BLACK

    appearance.headerTitleOffset = CGPoint(x: 0, y: 0)
    appearance.headerMinimumDissolvedAlpha = 0.6
    
    appearance.todayColor = COLOR_PRIMARY
    appearance.todaySelectionColor = COLOR_BLACK
    
    appearance.titleFont = UIFont(name: "SFProDisplay-Bold", size: 11)
    appearance.titleSelectionColor = COLOR_BLACK
    
    appearance.weekdayFont = UIFont(name: "SFProText-Semibold", size: 11)
    appearance.weekdayTextColor = COLOR_GREY
    appearance.eventDefaultColor = COLOR_BLACK
    
    appearance.subtitleFont = UIFont(name: "SFProDisplay-Bold", size: 20)
   
    
    appearance.selectionColor = COLOR_BLACK
    
    
}

}

Even though I am accessing the property .headerTitleFont it doesn't do anything ? I have tried all kinds of sizes. Any help appreciated, thank you.

字体大小问题

您提到的字体似乎在 simulator/device 中不可用,因此它默认为一种字体。我用 pre-installed 的字体尝试了您的方法,并且 headerTitle 按预期进行了更改。 pre-installedfonts

列表
appearance.headerTitleFont = UIFont(name: "Noteworthy Light", size: 60)

这是上面字体的显示方式

为 headerView 添加副标题

有了可用的 API,您似乎无法在 headerView 中设置字幕。但是您也可以通过自定义 FSCalendarHeaderCell.titleLabel.attributedText 来实现它,如下所示。请注意,下面的代码仅更改 collectionView.visibleCells 的文本,因此您还必须在滚动 headerView

时执行此代码
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    
    for cell in calendar.calendarHeaderView.collectionView.visibleCells {
        //create an attributedString with two lines and different font sizes
        let attributedString = NSMutableAttributedString(string: "Sep\n2021\n")
        
        let attributes0: [NSAttributedString.Key : Any] = [
            .foregroundColor: UIColor.yellow,
            .font: UIFont(name: "HelveticaNeue", size: 40)!
        ]
        let attributes1: [NSAttributedString.Key : Any] = [
            .foregroundColor: UIColor.systemGray2
        ]
        
        attributedString.addAttributes(attributes0, range: NSRange(location: 0, length: 3))
        attributedString.addAttributes(attributes1, range: NSRange(location: 4, length: 4))
        
        //replace titleLabel attributedText with the one we created
        (cell as! FSCalendarHeaderCell).titleLabel.attributedText = attributedString
    }
}

这是更改 FSCalendarHeaderCell.titleLabel

attributedText 后的样子