Skip to content

Instantly share code, notes, and snippets.

View sauvikatinnofied's full-sized avatar

Sauvik Dolui sauvikatinnofied

View GitHub Profile
@sauvikatinnofied
sauvikatinnofied / UIColorOldWay.swift
Last active December 31, 2016 13:16
Medium Blog ColorConstant
let shadowColor = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 1.0)
let shadowColorWithAlpha = UIColor(red: 204.0/255.0, green: 204.0/255.0, blue: 204.0/255.0, alpha: 0.5)
let customColorWithAlpha = UIColor(red: 18.0/255.0, green: 62.0/255.0, blue: 221.0/255.0, alpha: 0.25)
@sauvikatinnofied
sauvikatinnofied / UIColorNewWay.swift
Last active January 2, 2017 06:26
Medium Blog ColorConstant
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
@sauvikatinnofied
sauvikatinnofied / Utility.swift
Last active January 3, 2017 20:34
MediumBlogPost_FontHandling_Gist_1
class Utility {
/// Logs all available fonts from iOS SDK and installed custom font
class func logAllAvailableFonts() {
for family in UIFont.familyNames {
print("\(family)")
for name in UIFont.fontNames(forFamilyName: family) {
print(" \(name)")
}
}
@sauvikatinnofied
sauvikatinnofied / FontName_Size_Enum.swift
Last active January 3, 2017 22:53
MediumBlogPost_FontHandling_Gist_1
enum FontName: String {
case RobotoBlack = "Roboto-Black"
case RobotoBlackItalic = "Roboto-BlackItalic"
case RobotoBold = "Roboto-Bold"
case RobotoBoldItalic = "Roboto-BoldItalic"
case RobotoItalic = "Roboto-Italic"
case RobotoLight = "Roboto_Light"
case RobotoLightItalic = "Roboto-LightItalic"
case RobotoMedium = "Roboto-Medium"
case RobotoMediumItalic = "Roboto-MediumItalic"
@sauvikatinnofied
sauvikatinnofied / FontTypeSizeAllEnums.swift
Last active February 16, 2019 05:54
MediumBlogPost_FontHandling_Gist_3
enum FontType {
case installed(FontName)
case custom(String)
case system
case systemBold
case systemItatic
case systemWeighted(weight: Double)
case monoSpacedDigit(size: Double, weight: Double)
}
enum FontSize {
@sauvikatinnofied
sauvikatinnofied / FontWrapped1.swift
Last active January 3, 2017 22:53
MediumBlogPost_FontHandling_Gist_4
struct Font {
enum FontType {
case installed(FontName)
// ...
}
enum FontSize {
case standard(StandardSize)
// ...
}
enum FontName: String {
@sauvikatinnofied
sauvikatinnofied / FontWrapped2.swift
Last active January 3, 2017 22:54
MediumBlogPost_FontHandling_Gist_5
extension Font {
var instance: UIFont {
var instanceFont: UIFont!
switch type {
case .custom(let fontName):
guard let font = UIFont(name: fontName, size: CGFloat(size.value)) else {
fatalError("\(fontName) font is not installed, make sure it is added in Info.plist and logged with Utility.logAllAvailableFonts()")
}
instanceFont = font
case .installed(let fontName):
@sauvikatinnofied
sauvikatinnofied / FontUsagesOldWay.swift
Last active January 3, 2017 22:30
MediumFontUsagesBlogGist6
let system12 = UIFont.systemFont(ofSize: 12.0) // Hard coded literals -> 1
let robotoThin20 = UIFont(name: "Roboto-Thin", size: 20.0) // Hard coded literals -> 2
let robotoBlack14 = UIFont(name: "Roboto-Black", size: 14.0) // Hard coded literals -> 2
let helveticaLight13 = UIFont(name: "Helvetica-Light", size: 13.0) // Hard coded literals -> 2
@sauvikatinnofied
sauvikatinnofied / FontUsagesNew.swift
Created January 3, 2017 22:32
MediumBlogFontUsages8
let system12 = Font(.system, size: .standard(.h5)).instance
let robotoThin20 = Font(.installed(.RobotoThin), size: .standard(.h1)).instance
let robotoBlack14 = Font(.installed(.RobotoBlack), size: .standard(.h4)).instance
let helveticaLight13 = Font(.custom("Helvetica-Light"), size: .custom(13.0)).instance