Coder Social home page Coder Social logo

fontpicker's Introduction

FontPicker

A Font Picker in a similar style to Apple's Color Picker, providing a means of choosing a font from the available UIFont familyNames. I'm not 100% sure that all of these font names work in SwiftUI, but they seem to.

Example 1

Installation

Swift Package Manager

In Xcode:

Example

NB: All examples require import FontPicker at the top of the source file

It can be used directly as a view, which offers the full range of customisation options -

var body: some View {
    
    FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
        .additionalFontNames(["MySpecialFont"])
        .excludedFontNames(["Marker Felt"])
        .backgroundColor(viewModel.fontPickerBackgroundColor)
}

or as a modifier, which presents the default font picker (with no customisation options) -

var body: some View {

    MyView {
    
    }
    .fontPicker(isPresented: $isFontPickerPresented, Binding: $viewModel.selectedFont)
}

Specify the fonts you want to be shown

If you use this modifier, it will only show the fonts you specify

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .fontNames(viewModel.allTheBestFonts)

Specify the fonts you'd like to add to the default list

This will show all of the available system fonts, plus any you pass in here

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .additionalFontNames(viewModel.myUniqueFonts)

Specify the fonts you'd like to not be shown

This will show all of the available system fonts, minus any you pass in here

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .excludedFontNames(viewModel.rubbishFonts)

Disable the automatic "dismiss on selection" functionality

This might be necessary if you have (eg) a preview visible above the picker, where you can see how your selected font looks - the user can then decide when to dismiss the picker

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .disableDismissOnSelection

Set the picker's background colour

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .backgroundColor(.lightGray)

Set the height of the picker as either a fixed height or as a proportion of the containing view's height

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .height(.fixed(400))

or

FontPicker(isPresented: $isFontPickerPresented, selected: $viewModel.selectedFont)
    .height(.proportional(0.6))

Additionally...

There are two NotificationCenter notifications which are sent, which are defined as static vars on Notification.Name -

  • fontPickerAppeared ("FontPickerAppearedNotification")
  • fontPickerDisappeared ("FontPickerDisappearedNotification")

These are sent as their names suggest, and there is no additional userInfo

Dependencies

Requires HalfASheet, which is linked. Take a look at it here

Licence

FontPicker is available under the MIT licence

fontpicker's People

Contributors

franklynw avatar

Stargazers

Wayne Dahlberg avatar isontheline avatar Ilias Karim avatar  avatar Florian Schweizer avatar Rob Hudson avatar  avatar Gifton Okoronkwo avatar

Watchers

 avatar James Cloos avatar

fontpicker's Issues

System fonts not displaying

This is a very simple issue but I'm missing the default system fonts, i.e.:

  • SF Pro
  • SF Mono
  • SF Rounded
  • New York

They simply do not show in the list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.