Skip to content

Commit

Permalink
Ensure TableViewHeaderFooterView has a themed default text color and …
Browse files Browse the repository at this point in the history
…font style (#2076)

* Ensure that TableViewHeaderFooterView has a themed default text color for attributedStrings

* Updates to apply default fluent style

* Remove unneeded cast
  • Loading branch information
nodes11 authored Jul 25, 2024
1 parent 30b8885 commit 584aeed
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ios/FluentUI/Table View/TableViewHeaderFooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
let titleFont = tokenSet[.textFont].uiFont
if !isUsingAttributedTitle {
titleView.font = titleFont
} else {
updateAttributedTitleWithDefaultFluentThemeAttributes()
}

// offset text container to center its content
Expand All @@ -482,10 +484,27 @@ open class TableViewHeaderFooterView: UITableViewHeaderFooterView, TokenizedCont
if !isUsingAttributedTitle {
titleView.textColor = tokenSet[.textColor].uiColor
titleView.font = tokenSet[.textFont].uiFont
} else {
updateAttributedTitleWithDefaultFluentThemeAttributes()
}
titleView.linkColor = tokenSet[.linkTextColor].uiColor
}

private func updateAttributedTitleWithDefaultFluentThemeAttributes() {
if let attributedTitle = self.attributedTitle {
/// Create an attributed string with the default fluent text color and font for the given style
let attributedTitleWithFluentTheme = NSMutableAttributedString(string: attributedTitle.string, attributes: [NSAttributedString.Key.foregroundColor: tokenSet[.textColor].uiColor, NSAttributedString.Key.font: tokenSet[.textFont].uiFont])

/// Iterate over the attributes set by the consumer and apply them to our attributed string
attributedTitle.enumerateAttributes(in: NSRange(location: 0, length: attributedTitle.length)) { attributes, range, _ in
attributedTitleWithFluentTheme.addAttributes(attributes, range: range)
}

/// Update the `titleView` attributed string
titleView.attributedText = attributedTitleWithFluentTheme
}
}

private func updateLeadingViewColor() {
leadingView?.tintColor = tokenSet[.leadingViewColor].uiColor
}
Expand Down

0 comments on commit 584aeed

Please sign in to comment.