Created
May 28, 2019 05:39
-
-
Save Ilesh/19662fe6465b7b4f1d439167a77f3049 to your computer and use it in GitHub Desktop.
IPLookup is the one singleton class of the dropdown. It is very easy to manage dropdown in using single file. configuration is in the same place so easy to modify when the requirement changes. :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Lookup.swift | |
// | |
// | |
// Created by Ilesh's 2018 on 09/03/19. | |
// Copyright © 2019 Ilesh. All rights reserved. | |
// | |
import Foundation | |
/* | |
Add pod file for the dropdown list | |
pod 'DropDown' | |
Check here full details for pods | |
https://github.com/AssistoLab/DropDown | |
*/ | |
import DropDown | |
class Lookup { | |
static let shared : Lookup = Lookup() | |
//LIST | |
//let dropDown = DropDown() | |
lazy var dropDown : DropDown = { | |
let newDropDown = DropDown() | |
let appearance = DropDown.appearance() | |
appearance.cellHeight = 40 | |
appearance.backgroundColor = UIColor(white: 1, alpha: 1) | |
appearance.selectionBackgroundColor = UIColor(red: 0.6494, green: 0.8155, blue: 1.0, alpha: 0.2) | |
// appearance.separatorColor = UIColor(white: 0.7, alpha: 0.8) | |
appearance.shadowColor = UIColor(white: 0.6, alpha: 1) | |
appearance.animationduration = 0.25 | |
appearance.textColor = UIColor.label.red | |
// appearance.textFont = UIFont(name: "Georgia", size: 14) | |
if #available(iOS 11.0, *) { | |
appearance.setupMaskedCorners([.layerMaxXMaxYCorner, .layerMinXMaxYCorner]) | |
} | |
/*newDropDown.cellNib = UINib(nibName: "AddLabelCell", bundle: nil) | |
newDropDown.customCellConfiguration = { (index: Index, item: String, cell: DropDownCell) -> Void in | |
guard let cell = cell as? AddLabelCell else { return } | |
// Setup your custom UI components | |
//cell.viewLabel.backgroundColor = UIColor.hexString(self.arrColorLabel[index]) | |
cell.viewLabel.layer.cornerRadius = cell.viewLabel.frame.height / 2 | |
cell.viewLabel.layer.masksToBounds = true | |
}*/ | |
return newDropDown | |
}() | |
func show(view:UIView,data:[String], selection: @escaping (_ index:Int,_ item:String) -> Void ) { | |
dropDown.anchorView = view | |
dropDown.bottomOffset = CGPoint(x: 0, y: view.bounds.height) | |
dropDown.dataSource = data | |
dropDown.selectionAction = { [weak self] (index, item) in | |
selection(index,item) | |
} | |
dropDown.show() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment