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
- name: Swift by Sundell | |
rss_url: https://swiftbysundell.com/rss | |
logo_url: https://www.google.com/s2/favicons?sz=256&domain_url=www.swiftbysundell.com | |
- name: Swift Wings | |
rss_url: https://www.onswiftwings.com/index.xml | |
- name: Swift Rocks | |
rss_url: https://swiftrocks.com/rss.xml |
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
label.font = UIFont.jurassicPark.regular.sized(40.0).scaled(forTextStyle: .body, maxSize: 80.0) |
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
label.font = UIFont.jurassicPark.semibold.sized(30.0) |
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
protocol CustomFont { | |
func sized(_ size: CGFloat) -> UIFont? | |
} | |
extension CustomFont where Self: RawRepresentable, Self.RawValue == String { | |
func sized(_ size: CGFloat) -> UIFont? { | |
return UIFont(name: self.rawValue, size: size) | |
} | |
} |
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
extension CustomFont where Self: RawRepresentable, Self.RawValue == String { | |
func sized(_ size: CGFloat) -> UIFont { | |
return UIFont(name: self.rawValue, size: size).unwrapped | |
} | |
} |
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
@IBOutlet weak var outletLabel: UILabel! | |
private lazy var titleLabel: UILabel = UILabel.scaledTitle | |
private func setupLabels() { | |
view.addSubview(titleLabel) | |
outletLabel.font = UIFont.jurassicPark.bold.scaled(forTextStyle: .body, maxSize: 30.0) | |
outletLabel.text = "Dinosaur" | |
} |
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
extension UILabel { | |
static var scaledTitle: UILabel { | |
let label = UILabel() | |
label.adjustsFontForContentSizeCategory = true | |
label.font = UIFont.jurassic.scaled | |
label.numberOfLines = 0 | |
return label | |
} | |
} |
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
extension Optional where Wrapped == UIFont { | |
var unwrapped: Wrapped { | |
switch self { | |
case .some(let font): return font | |
case .none: | |
preconditionFailure(""" | |
Could not load font from available fonts: | |
\(UIFont.familyNames.joined(separator: ", ")) | |
""") |
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
extension UIFont { | |
enum jurassicPark: String, CustomFont { | |
case | |
regular = "JurassicPark-Regular", | |
semibold = "JurassicPark-Semibold", | |
bold = "JurassicPark-Bold" | |
} | |
} |
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
protocol ScalableFont { | |
func scaled(forTextStyle textStyle: UIFont.TextStyle?, maxSize: CGFloat?) -> UIFont | |
} | |
extension UIFont: ScalableFont { | |
func scaled(forTextStyle textStyle: UIFont.TextStyle? = nil, maxSize: CGFloat? = nil) -> UIFont { | |
let fontMetrics = textStyle != nil ? UIFontMetrics(forTextStyle: textStyle!) : UIFontMetrics.default | |
if let maxSize = maxSize { | |
return fontMetrics.scaledFont(for: self, maximumPointSize: maxSize) | |
} |
NewerOlder