tyagishi / FontPicker

FontPicker on macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FontPicker

Wrapped NSFontPanel for SwiftUI.

UI

FontPickerExample

for working example, please refer to https://github.com/tyagishi/FontPickerExample

example code

FontPicker can be used like ColorPicker.

struct ContentView: View {
    @State private var font: NSFont = NSFont.systemFont(ofSize: 24)
    var body: some View {
        VStack {
            FontPicker("Font", selection: $font)
            Text("selected font name \(font.displayName ?? "no font" )")
            Text("font size: \(font.pointSize, specifier: "%.0f")")
        }
    }
}

small improvement

As usual user can close FontPanel with close button of FontPanel. Additionally: user can close FontPanel with second clicking FontPicker button. (i.e. Clicking FontPicker button while FontPanel is still open FontPanel will be closed.)

comments are welcome

Comments, advice for improvements are highly appreciated. please contact to https://twitter.com/tyagishi .

About

FontPicker on macOS

License:MIT License


Languages

Language:Swift 100.0%