38 lines
931 B
Swift
38 lines
931 B
Swift
//
|
|
// UIKit+Extensions.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Andrea Busi on 05/04/21.
|
|
// Copyright © 2021 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
|
|
extension UIButton {
|
|
|
|
func setLocalizedTitle(key: String, uppercased: Bool = true, emoji: String? = nil) {
|
|
var title = NSLocalizedString(key, comment: "")
|
|
if uppercased {
|
|
title = title.uppercased()
|
|
}
|
|
if let emoji = emoji {
|
|
title = "\(title) \(emoji)"
|
|
}
|
|
setTitle(title, for: .normal)
|
|
}
|
|
}
|
|
|
|
|
|
extension UIView {
|
|
/// Creates a snapshot of the current view
|
|
/// - Returns: Image with the snapshot of the view
|
|
public func createSnapshot() -> UIImage {
|
|
let renderer = UIGraphicsImageRenderer(size: bounds.size)
|
|
let image = renderer.image { ctx in
|
|
drawHierarchy(in: bounds, afterScreenUpdates: true)
|
|
}
|
|
return image
|
|
}
|
|
}
|