Skip to content

Instantly share code, notes, and snippets.

View giovani-pereira-ifood's full-sized avatar

Giovani Nascimento Pereira giovani-pereira-ifood

View GitHub Profile
enum Icon: String, CaseIterable {
case bag = "\u{e807}"
case bank = "\u{e808}"
case batteryout = "\u{e809}"
case battery = "\u{e80a}"
case bike = "\u{e80b}"
case bulb = "\u{e80c}"
case calendar = "\u{e80d}"
...
class IconView: UIView {
var icon: Icon
var color: UIColor
private let label: UILabel = {
let font = UIFont.iconFont(ofSize: 500)
let label = UILabel()
label.font = font
label.adjustsFontSizeToFitWidth = true
extension Icon {
func callAsFunction(color: UIColor = .black) -> IconView {
IconView(icon: self, color: color)
}
}
class IconView: UIView {
/// Change the icon being displayed
var icon: Icon {
didSet {
label.text = icon.rawValue
}
}
/// Change the color of the icon being displayed
var color: UIColor {
[{
"name": "alert",
"char": "🔔"
},
{
"name": "car",
"char": "🚘"
}]
enum Icon {
case alert
case car
case person
...
}
extension Icon {
var stringValue: String? {
let items = JSONDecoder().decode([IconDescription], from: json)
class IconView: UIView {
private func setupAccessibility() {
label.isAccessibilityElement = false
isAccessibilityElement = false
shouldGroupAccessibilityChildren = true
}
}
@giovani-pereira-ifood
giovani-pereira-ifood / loadLottieAnimationFromJSON.swift
Created December 17, 2020 19:26
load Lottie animation from JSON
guard let jsonString = UserDefaults.shared.string(forKey: .splashAnimation),
  let data = jsonString.data(using: .utf8),
  let animation = try? JSONDecoder().decode(Animation.self, from: data) else { return }
animationView = AnimationView(animation: animation)
@giovani-pereira-ifood
giovani-pereira-ifood / animation-download,json
Last active December 18, 2020 11:40
animation download json
[{
"startDate": "YYYY-MM-dd",
"endDate": "YYYY-MM-dd",
"animation": { ... }
},
{
"startDate": "YYYY-MM-dd",
"endDate": "YYYY-MM-dd",
"animation": { ... }
}]
func createSnapshot(from icon: Icon) -> UIImage {
// Create view and add as subview on the window
let window: UIWindow = UIApplication.shared.keyWindow ?? UIWindow()
let iconView = IconView(icon: icon)
window.addSubview(iconView)
// Set a default size for all the snapshots
iconView.frame = CGRect(origin: .zero, size: dataImageStorageSize)
// Take a snapshot