Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default fonts are changed to system fonts. #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 4 additions & 54 deletions Presentr/AlertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ public enum AlertActionStyle {

}

private enum Font: String {

case Montserrat = "Montserrat-Regular"
case SourceSansPro = "SourceSansPro-Regular"

func font(_ size: CGFloat = 15.0) -> UIFont {
return UIFont(name: self.rawValue, size: size)!
}

}

private struct ColorPalette {

static let grayColor = UIColor(red: 151.0/255.0, green: 151.0/255.0, blue: 151.0/255.0, alpha: 1)
Expand Down Expand Up @@ -191,14 +180,10 @@ public class AlertViewController: UIViewController, CornerRadiusSettable {
}

private func setupFonts() {
if titleFont == nil || bodyFont == nil || buttonFont == nil {
loadFonts
}

titleLabel.font = titleFont ?? Font.Montserrat.font()
bodyLabel.font = bodyFont ?? Font.SourceSansPro.font()
firstButton.titleLabel?.font = buttonFont ?? Font.Montserrat.font(11.0)
secondButton.titleLabel?.font = buttonFont ?? Font.Montserrat.font(11.0)
titleLabel.font = titleFont ?? UIFont.boldSystemFont(ofSize: 17)
bodyLabel.font = bodyFont ?? UIFont.systemFont(ofSize: 15, weight: .medium)
firstButton.titleLabel?.font = buttonFont ?? UIFont.boldSystemFont(ofSize: 17)
secondButton.titleLabel?.font = buttonFont ?? UIFont.systemFont(ofSize: 15, weight: .medium)
}

private func setupLabels() {
Expand Down Expand Up @@ -246,38 +231,3 @@ public class AlertViewController: UIViewController, CornerRadiusSettable {
}

}

// MARK: - Font Loading

let loadFonts: () = {
let loadedFontMontserrat = AlertViewController.loadFont(Font.Montserrat.rawValue)
let loadedFontSourceSansPro = AlertViewController.loadFont(Font.SourceSansPro.rawValue)
if loadedFontMontserrat && loadedFontSourceSansPro {
print("LOADED FONTS")
}
}()

extension AlertViewController {

static func loadFont(_ name: String) -> Bool {
let bundle = Bundle(for: self)
guard let fontPath = bundle.path(forResource: name, ofType: "ttf"),
let data = try? Data(contentsOf: URL(fileURLWithPath: fontPath)),
let provider = CGDataProvider(data: data as CFData),
let font = CGFont(provider)
else {
return false
}

var error: Unmanaged<CFError>?

let success = CTFontManagerRegisterGraphicsFont(font, &error)
if !success {
print("Error loading font. Font is possibly already registered.")
return false
}

return true
}

}
Binary file removed Presentr/Montserrat-Regular.ttf
Binary file not shown.
Binary file removed Presentr/SourceSansPro-Regular.ttf
Binary file not shown.