Skip to content

Commit

Permalink
Wrote ReadMe & added example image
Browse files Browse the repository at this point in the history
  • Loading branch information
franklynw committed Feb 4, 2021
1 parent f68038a commit 06398ad
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
96 changes: 95 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,97 @@
# FontPicker

A description of this package.
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.

<img src="Resources//Example1.png" alt="Example 1"/>

## Installation

### Swift Package Manager

In Xcode:
* File ⭢ Swift Packages ⭢ Add Package Dependency...
* Use the URL https://github.com/franklynw/FontPicker


## 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 -

```swift
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) -

```swift
var body: some View {

MyView {

}
.fontPicker(isPresented: $isFontPickerPresented, Binding: $viewModel.selectedFont) {
// your view here
}
}
```

### Specify the fonts you want to be shown

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

```swift
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

```swift
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

```swift
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

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

### Set the picker's background colour

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


## Dependencies

Requires HalfASheet, which is linked. Take a look at it [here](https://github.com/franklynw/HalfASheet)


## License

`FontPicker` is available under the MIT license
Binary file added Resources/Example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 06398ad

Please sign in to comment.