Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yspreen/a7b3dc9857e0c98e81b59a4f47580b5e to your computer and use it in GitHub Desktop.
Save yspreen/a7b3dc9857e0c98e81b59a4f47580b5e to your computer and use it in GitHub Desktop.
//
// ContentView.swift
//
// Created by @spreen_co on 11/13/22.
//
import SwiftUI
struct ContentView: View {
var body: some View {
Text(attributedString)
}
var attributedString: AttributedString {
var attributes = AttributeContainer()
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 20
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))
}
}
func Text(_ content: AttributedString) -> some View {
SwiftUI.Text(content)
.lineSpacing(content.paragraphStyle?.lineSpacing ?? 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment