SwiftMarkdown is library for parsing and formatting strings with markdown tags
To have your label formatted like the above your code would look like the following:
let string = """
Swift **Markdown** Library
Swift ~~Markdown~~ Library
Swift *Markdown* Library
Swift ~~**Markdown**~~ Library
""".uppercased()
label.attributedText = string.markdown(font: label.font)
Or if you already have a NSAttributedString
, simply add the markdown tags to your string and use the markdown
property:
let string = "SWIFT **MARKDOWN** LIBRARY"
let attributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20)]
let attributed = NSAttributedString(string: string, attributes: attributes)
label.attributedText = attributed.markdown
pod 'SwiftMarkdown'
Add the following as a dependency to your Package.swift:
.package(url: "https://github.com/viniciusaro/SwiftMarkdown.git", .upToNextMajor(from: "0.0.2"))
You also need to specify "SwiftMarkdown" as a dependency of the Target in which you wish to use SwiftMarkdown.
...
targets: [
.target(
name: "MyApp",
dependencies: ["SwiftResolver", "SwiftMarkdown"]),
...
*Italic*
**Bold**
~~Strikethrough~~
# H1
## H2
### H3
#### H4
##### H5
###### H6
SwiftMarkdown is released under an MIT license.