Skip to content

Instantly share code, notes, and snippets.

View mhijack's full-sized avatar
🎯
Focusing

Jianyuan Chen mhijack

🎯
Focusing
View GitHub Profile
struct EmptyTableViewCellModel {
var icon: UIImage
var descriptionText: String
var secondaryText: String
var actionText: String
var action: (() -> ())?
init(icon: UIImage = UIImage(named: "default-empty-image")!,
descriptionText: String = NSLocalizedString("empty-cell-description", value: "It's kinda lonely out there", comment: "Empty table view cell description text"),
class EmptyTableViewCell: UITableViewCell {
var emptyModel: EmptyTableViewCellModel?
public func setContent(emptyModel: EmptyTableViewCellModel) {
self.emptyModel = emptyModel
}
}
import Stevia
class OverflowLauncher: NSObject {
var backgroundView: UIView?
var menuView: UIView?
func testAddView() {
guard let window = UIApplication.shared.windows.first else { return }
let backgroundView = UIView(frame: window.bounds)
class ViewController: UIViewController {
@IBOutlet weak var showOptionButton: UIBarButtonItem!
@IBOutlet weak var chosenOptionLabel: UILabel!
private lazy var optionsManager: OptionsManager = {
let manager = HomeOptionsManager(options: ["Canelo", "GGG", "Mayweather"])
manager.optionsDidOpen = {
print("Menu is now open")
protocol OptionsManager {
var options: [String] { get }
func showOptions()
}
class HomeOptionsManager: NSObject, OptionsManager {
/// Use private(set) to mark the setter private
private(set) var options: [String]
private let TABLE_CELL_HEIGHT: CGFloat = 44
private var tableViewHeight: CGFloat {
return TABLE_CELL_HEIGHT * CGFloat(options.count) + (UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0) /// Taking into account the bottom safe area for full-screen iphones
}
extension HomeOptionsManager: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return options.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = options[indexPath.row]
return cell
class HomeOptionsManager: NSObject, OptionsManager {
/// Use private(set) to mark the setter private
private(set) var options: [String]
private let TABLE_CELL_HEIGHT: CGFloat = 44
private var tableViewHeight: CGFloat {
return TABLE_CELL_HEIGHT * CGFloat(options.count) + (UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0) /// Taking into account the bottom safe area for full-screen iphones
}
extension HomeOptionsManager {
/// Configures options view and add to screen
public func showOptions() {
guard backgroundView == nil else { return }
guard let window = UIApplication.shared.windows.first else { return }
/// The background view that covers the entire screen
let backgroundView = UIView(frame: window.bounds)
backgroundView.backgroundColor = .black
@mhijack
mhijack / ioslocaleidentifiers.csv
Created April 29, 2021 17:45 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)