README.md 3.5 KB
Newer Older
N
Nicholas Maccharoli 已提交
1 2
# UIFontComplete
[![Build Status](https://travis-ci.org/Nirma/UIFontComplete.svg?branch=master)](https://travis-ci.org/Nirma/UIFontComplete)
N
Nicholas Maccharoli 已提交
3 4
![Swift 4.1](https://img.shields.io/badge/Swift-4.0-orange.svg)
![Swift 4.2](https://img.shields.io/badge/Swift-4.0-orange.svg)
N
Nicholas Maccharoli 已提交
5
![platforms](https://img.shields.io/badge/platforms-iOS%20%7C%20tvOS-333333.svg)
N
Nicholas Maccharoli 已提交
6 7
![CodeCov](https://img.shields.io/codecov/c/github/Nirma/UIFontComplete.svg)
[![CocoaPods compatible](https://img.shields.io/cocoapods/v/UIFontComplete.svg)](#cocoapods)
N
Nicholas Maccharoli 已提交
8
[![CocoaPods](https://img.shields.io/cocoapods/dt/UIFontComplete.svg)]()
N
Nicholas Maccharoli 已提交
9
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
N
Nicholas Maccharoli 已提交
10
 [![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
N
Nicholas Maccharoli 已提交
11 12
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)

N
Nicholas Maccharoli 已提交
13
Font management (System & Custom) for iOS and tvOS
N
Nicholas Maccharoli 已提交
14 15

## Usage 
N
Nicholas Maccharoli 已提交
16
No more wasted time searching for names of `UIFont` fonts and no more surprises at runtime if a font name was mistyped.
N
Nicholas Maccharoli 已提交
17
This library is simply one extension to `UIFont` and one `Font` `enum` with a case for each system font on iOS and tvOS. 
N
Nicholas Maccharoli 已提交
18
Custom font support is also available, please keep reading for details!
N
Nicholas Maccharoli 已提交
19

20
Instead of using the `String` based constructor native to `UIFont`:
N
Nicholas Maccharoli 已提交
21 22 23 24 25 26 27 28 29

```swift
let font = UIFont(name: "Arial-BoldItalicMT", size: 12.0)
```

You can now simply start typing the name of the font enum and let code completion help you:

![](http://i.imgur.com/yBYRQVB.gif)

30 31 32 33 34 35
This library currently provides two different options for creating `UIFont` objects.
The first is calling the font name off of the provided `Font` enumeration and then calling `of(size:)`
to provide the desired size.
 
```swif
let myFont = Font.helvetica.of(size: 12.0)
N
Nicholas Maccharoli 已提交
36 37
```

38 39 40
The other `UIFont` creation method offered by this library is similar to the normal `UIFont`
constructor except that instead of providing a `String` of the desired font, a case of the `Font` enum is provided instead.
 
N
Nicholas Maccharoli 已提交
41
```swift
42
let font = UIFont(font: .arialBoldItalicMT, size: 12.0)
N
Nicholas Maccharoli 已提交
43 44
```

N
Nicholas Maccharoli 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
### What about Custom Fonts?
Custom Fonts can be added with the help of the `FontRepresentable` protocol.
Simply create your own `CustomFont` `String` based enumeration that adapts the 
`FontRepresentable` and add a case per font that you want to add like so:

```swift
// In your project using custom fonts

enum CustomFont: String, FontRepresentable {
    case alexBrushRegular = "AlexBrush-Regular"
}

CustomFont.alexBrushRegular.of(size: 12.0) // => UIFont
```


N
Nicholas Maccharoli 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
## Installation

#### Carthage

If you use Carthage to manage your dependencies, simply add
UIFontComplete to your `Cartfile`:

```
github "Nirma/UIFontComplete"
```

If you use Carthage to build your dependencies, make sure you have added `UIFontComplete.framework` to the "_Linked Frameworks and Libraries_" section of your target, and have included `UIFontComplete.framework` in your Carthage framework copying build phase.

#### CocoaPods

If you use CocoaPods to manage your dependencies, simply add
UIFontComplete to your `Podfile`:

```
pod 'UIFontComplete'
```

## Requirements

N
Nicholas Maccharoli 已提交
85 86
* Xcode 9.0
* Swift 4.0+
N
Nicholas Maccharoli 已提交
87

N
Nicholas Maccharoli 已提交
88 89 90
## Contributing to UIFontComplete
**Pull Requests are Welcome!**
If you feel that this library could be made better then please do so by sending over a pull request! 
N
Nicholas Maccharoli 已提交
91 92 93 94 95 96

## License

UIFontComplete is free software, and may be redistributed under the terms specified in the [LICENSE] file.

[LICENSE]: /LICENSE