Last active
December 27, 2021 00:46
-
-
Save mntone/9e0f57964cb30324eec1247e796a5e7c to your computer and use it in GitHub Desktop.
Copyright (C) 2021 mntone. All right reserved. This source code is under MIT license.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(macOS 12.0, iOS 15.0, tvOS 15.0, watchOS 8.0, *) | |
func coloredPrimaryColor(localized: String.LocalizationValue) -> AttributedString { | |
var attributedString: AttributedString = AttributedString(localized: localized) | |
guard let firstBoldRange = attributedString.range(of: "**") else { return attributedString } | |
let orig: AttributedString = attributedString | |
attributedString.removeSubrange(firstBoldRange) | |
guard let nextBoldRange = attributedString.range(of: "**") else { return orig } | |
attributedString.removeSubrange(nextBoldRange) | |
var attribute: AttributeContainer = AttributeContainer() | |
attribute.foregroundColor = .primary | |
attribute.font = .footnote.bold() // MARK: AttributeContainer を生成するのにオリジナルの Font 情報が必要になる | |
attributedString[firstBoldRange.lowerBound..<nextBoldRange.lowerBound].mergeAttributes(attribute) | |
return attributedString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment