diff --git a/ios/FluentUI.Demo/FluentUI.Demo/Demos/TableViewHeaderFooterViewDemoController.swift b/ios/FluentUI.Demo/FluentUI.Demo/Demos/TableViewHeaderFooterViewDemoController.swift index 79bd0dfce..049294dfd 100644 --- a/ios/FluentUI.Demo/FluentUI.Demo/Demos/TableViewHeaderFooterViewDemoController.swift +++ b/ios/FluentUI.Demo/FluentUI.Demo/Demos/TableViewHeaderFooterViewDemoController.swift @@ -126,7 +126,7 @@ extension TableViewHeaderFooterViewDemoController { if section.footerLinkText.isEmpty { footer?.setup(style: .footer, title: section.footerText) } else { - let title = NSMutableAttributedString(string: section.footerText) + let title = NSMutableAttributedString(string: section.footerText, attributes: [NSAttributedString.Key.foregroundColor: footer?.tokenSet[.textColor].uiColor ?? .white]) let range = (title.string as NSString).range(of: section.footerLinkText) if range.location != -1 { title.addAttribute(.link, value: "https://github.com/microsoft/fluentui-apple", range: range) diff --git a/ios/FluentUI/Table View/TableViewHeaderFooterView.swift b/ios/FluentUI/Table View/TableViewHeaderFooterView.swift index 11fe06631..6b1b4a0e6 100644 --- a/ios/FluentUI/Table View/TableViewHeaderFooterView.swift +++ b/ios/FluentUI/Table View/TableViewHeaderFooterView.swift @@ -320,17 +320,12 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont accessoryButtonTitle: String = "", accessoryView: UIView? = nil, leadingView: UIView? = nil) { - attributedTitleFont = nil - attributedTitleColor = nil - - if let attributedTitle = attributedTitle { + if let attributedTitle { + self.attributedTitle = attributedTitle titleView.attributedText = attributedTitle titleView.isSelectable = true - - let attributes = attributedTitle.attributes(at: 0, effectiveRange: nil) - attributedTitleFont = attributes[NSAttributedString.Key.font] as? UIFont ?? tokenSet[.textFont].uiFont - attributedTitleColor = attributes[NSAttributedString.Key.foregroundColor] as? UIColor ?? tokenSet[.textColor].uiColor } else { + self.attributedTitle = nil titleView.attributedText = NSAttributedString(string: " ") // to clear attributes titleView.text = title titleView.isSelectable = false @@ -458,8 +453,10 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont private func updateTitleViewFont() { if let window = window { - let titleFont = attributedTitleFont ?? tokenSet[.textFont].uiFont - titleView.font = titleFont + let titleFont = tokenSet[.textFont].uiFont + if !isUsingAttributedTitle { + titleView.font = titleFont + } // offset text container to center its content #if os(iOS) @@ -474,8 +471,6 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont } private func updateTitleAndBackgroundColors() { - titleView.textColor = attributedTitleColor ?? tokenSet[.textColor].uiColor - if tableViewCellStyle == .grouped { backgroundView?.backgroundColor = tokenSet[.backgroundColorGrouped].uiColor } else if tableViewCellStyle == .plain { @@ -484,7 +479,10 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont backgroundView?.backgroundColor = .clear } - titleView.font = attributedTitleFont ?? tokenSet[.textFont].uiFont + if !isUsingAttributedTitle { + titleView.textColor = tokenSet[.textColor].uiColor + titleView.font = tokenSet[.textFont].uiFont + } titleView.linkColor = tokenSet[.linkTextColor].uiColor } @@ -524,8 +522,13 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont onHeaderViewTapped?() } - private var attributedTitleFont: UIFont? - private var attributedTitleColor: UIColor? + private var attributedTitle: NSAttributedString? { + didSet { + isUsingAttributedTitle = attributedTitle != nil + } + } + + private var isUsingAttributedTitle: Bool = false } // MARK: - TableViewHeaderFooterView: UITextViewDelegate