Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krzyzanowskim/coretextswift
CoreText Swift bindings
https://github.com/krzyzanowskim/coretextswift
coretext swift
Last synced: 20 days ago
JSON representation
CoreText Swift bindings
- Host: GitHub
- URL: https://github.com/krzyzanowskim/coretextswift
- Owner: krzyzanowskim
- License: mit
- Created: 2020-06-13T21:58:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-20T13:13:45.000Z (almost 2 years ago)
- Last Synced: 2024-04-14T07:11:17.824Z (7 months ago)
- Topics: coretext, swift
- Language: Swift
- Homepage: https://swift.best
- Size: 22.5 KB
- Stars: 146
- Watchers: 5
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CoreTextSwift
Swifty CoreText API.
CoreText is C API. This library is a set of wrappers and extensions that makes it convenient to work with Swift.
## Example
Draw line in currect graphics context
```swift
guard let ctx = UIGraphicsGetCurrentContext() else {
return
}let attributedString = NSAttributedString(string: "abcdefgh")
ctx.draw(attributedString.line())
```Use Glyph Run
```swift
let attributedString = NSAttributedString(string: "abcdefgh")for run in attributedString.line().glyphRuns() {
let font = run.font
for glyph in run.glyphs() {
let glyphPath = font.path(for: glyph)
}
}
```Draw Glyph Run to CGContext
```swift
guard let ctx = UIGraphicsGetCurrentContext() else {
return
}for run in attributedString.line().glyphRuns() {
run.draw(in: ctx)
}
```