-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Font.swift | ||
// Panda | ||
// | ||
// Created by Javier on 11/2/16. | ||
// Copyright © 2016 Javier. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public protocol FontContainer { | ||
func font(_ value: UIFont?) -> Self | ||
} | ||
|
||
extension FontContainer { | ||
@discardableResult | ||
public func font(style: UIFontTextStyle) -> Self { | ||
return font(.preferredFont(forTextStyle: style)) | ||
} | ||
|
||
@discardableResult | ||
public func font(size: CGFloat) -> Self { | ||
return font(.systemFont(ofSize: size)) | ||
} | ||
|
||
@available(iOS 8.2, *) | ||
@discardableResult | ||
public func font(size: CGFloat, weight: UIFont.Weight) -> Self { | ||
return font(.systemFont(ofSize: size, weight: weight)) | ||
} | ||
|
||
@discardableResult | ||
public func font(boldSize size: CGFloat) -> Self { | ||
return font(.boldSystemFont(ofSize: size)) | ||
} | ||
|
||
@discardableResult | ||
public func font(italicSize size: CGFloat) -> Self { | ||
return font(.italicSystemFont(ofSize: size)) | ||
} | ||
|
||
@available(iOS 9.0, *) | ||
@discardableResult | ||
public func font(monospacedDigitSize size: CGFloat, weight: UIFont.Weight) -> Self { | ||
return font(.monospacedDigitSystemFont(ofSize: size, weight: weight)) | ||
} | ||
} | ||
|
||
extension UILabel: FontContainer {} | ||
extension UITextField: FontContainer {} | ||
extension UITextView: FontContainer {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// UIFontExtensions.swift | ||
// Panda | ||
// | ||
// Created by Javier on 11/2/16. | ||
// Copyright © 2016 Javier. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
@available(iOS 8.2, *) | ||
extension UIFont { | ||
public enum Weight { | ||
case ultraLight, thin, light, regular, medium, semibold, bold, heavy, black | ||
case custom(CGFloat) | ||
|
||
fileprivate var rawValue: CGFloat { | ||
switch self { | ||
case .ultraLight: return UIFontWeightUltraLight | ||
case .thin: return UIFontWeightThin | ||
case .light: return UIFontWeightLight | ||
case .regular: return UIFontWeightRegular | ||
case .medium: return UIFontWeightMedium | ||
case .semibold: return UIFontWeightSemibold | ||
case .bold: return UIFontWeightBold | ||
case .heavy: return UIFontWeightHeavy | ||
case .black: return UIFontWeightBlack | ||
case let .custom(raw): return raw | ||
} | ||
} | ||
} | ||
|
||
public class func systemFont(ofSize fontSize: CGFloat, weight: Weight) -> UIFont { | ||
return systemFont(ofSize: fontSize, weight: weight.rawValue) | ||
} | ||
|
||
@available(iOS 9.0, *) | ||
public class func monospacedDigitSystemFont(ofSize fontSize: CGFloat, weight: Weight) -> UIFont { | ||
return monospacedDigitSystemFont(ofSize: fontSize, weight: weight.rawValue) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters