Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created November 15, 2022 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save christianselig/35e8fc46a39551ef9214070561a78ed2 to your computer and use it in GitHub Desktop.
Save christianselig/35e8fc46a39551ef9214070561a78ed2 to your computer and use it in GitHub Desktop.
struct ContentView: View {
var body: some View {
Text(attributedString)
}
var attributedString: AttributedString {
var attributes = AttributeContainer()
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 10.0
paragraphStyle.lineHeightMultiple = 100.0
paragraphStyle.paragraphSpacing = 20.0
attributes.paragraphStyle = paragraphStyle
var attributedString = AttributedString("Once upon a time there was a duck who lived in a pond and the duck's name was Henry", attributes: attributes)
let duckRange = attributedString.range(of: "duck")!
attributedString[duckRange].foregroundColor = .white
attributedString[duckRange].backgroundColor = .green
return attributedString
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewLayout(.fixed(width: 200.0, height: 200.0))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment