Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Sources/UIOnboarding/Views/UIOnboardingTitleLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,24 @@ extension UIOnboardingTitleLabel {

func updateFontSize(_ fontSize: CGFloat) {
guard let attributedString = attributedText else { return }
let originalFont = font
let mutableAttributedString = NSMutableAttributedString(attributedString: attributedString)

// Update the label's base font
let updatedBaseFont = font.withSize(fontSize)
self.font = updatedBaseFont

// Update fonts in the attributed string
mutableAttributedString.enumerateAttributes(in: NSRange(location: 0,
length: mutableAttributedString.length),
options: []) { attributes, range, _ in
if let font = attributes[.font] as? UIFont {
let multiplier = font.pointSize / (originalFont?.pointSize ?? font.pointSize)
let newFont = font.withSize(fontSize * multiplier)
if let existingFont = attributes[.font] as? UIFont {
// If font is already set in attributed string, preserve relative sizing
let multiplier = existingFont.pointSize / self.font.pointSize
let newFont = existingFont.withSize(fontSize * multiplier)
mutableAttributedString.addAttribute(.font, value: newFont, range: range)
} else {
// If no font is set, apply the base font
mutableAttributedString.addAttribute(.font, value: updatedBaseFont, range: range)
}
}

Expand Down