Created
November 15, 2022 16:07
-
-
Save christianselig/35e8fc46a39551ef9214070561a78ed2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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