iOS 15 includes support for AttributedString
Example
struct PlaygroundView: View {
func attributedString(string: String) -> AttributedString {
var text = AttributedString(string)
text.font = .largeTitle.bold()
text.foregroundColor = .blue
return text
}
var body: some View {
Text(attributedString(string: "Hello"))
}
}
Documentation mentions Attribute Scopes
The AttributedString API defines keys for common uses, such as text styling, semantically marking up formattable types like dates and numbers, and hyperlinking. You can find these in the AttributeScopes enumeration, which contains attributes for Foundation, SwiftUI, UIKit, and AppKit.
Here's strokeColor for the stroke color attribute, but it appears to do nothing.
struct PlaygroundView: View {
func attributedString(string: String) -> AttributedString {
var text = AttributedString(string)
text.font = .largeTitle.bold()
text.foregroundColor = .blue
text.strokeWidth = 5
text.strokeColor = .red
return text
}
var body: some View {
Text(attributedString(string: "Hello"))
}
}
Additional docs:
Foundation attributes https://developer.apple.com/documentation/foundation/attributescopes/foundationattributes
SwiftUI attributes https://developer.apple.com/documentation/foundation/attributescopes/swiftuiattributes
UIKit attributes https://developer.apple.com/documentation/foundation/attributescopes/uikitattributes
AppKit attributes https://developer.apple.com/documentation/foundation/attributescopes/appkitattributes
