53 lines
1.7 KiB
Swift
53 lines
1.7 KiB
Swift
//
|
|
// CommonViewSelectCurrencyList.swift
|
|
// List
|
|
//
|
|
// Created by Saveliy Stavitsky on 7/23/20.
|
|
// Copyright © 2020 Igor Danich. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class CommonViewPopUpSelection: UIStackView {
|
|
|
|
var selection: ((Int) -> Void)?
|
|
|
|
convenience init(list: [String],
|
|
selectedIndex: Int? = nil,
|
|
titlesDefaultColor: UIColor = Asset.lightGray.color,
|
|
selection: ((Int) -> Void)? = nil) {
|
|
self.init()
|
|
self.selection = selection
|
|
|
|
axis = .vertical
|
|
|
|
for item in list.enumerated() {
|
|
let button = UIButton()
|
|
button.setTitle(item.element, for: .normal)
|
|
button.heightAnchor.constraint(equalToConstant: 62).isActive = true
|
|
button.tag = item.offset
|
|
button.addTarget(self, action: #selector(buttonPressed(_:)), for: .touchUpInside)
|
|
button.contentHorizontalAlignment = .left
|
|
button.contentEdgeInsets.left = 16.0
|
|
button.titleLabel?.font = FontFamily.GolosUI.medium.font(size: 14)
|
|
|
|
let titleColor = selectedIndex == item.offset ? Asset.dark.color : titlesDefaultColor
|
|
button.setTitleColor(titleColor, for: .normal)
|
|
|
|
let separatorView = UIView()
|
|
separatorView.backgroundColor = Asset.lightGray.color
|
|
separatorView.alpha = 0.5
|
|
separatorView.heightAnchor.constraint(equalToConstant: 1).isActive = true
|
|
|
|
let stackView = UIStackView(arrangedSubviews: [button, separatorView])
|
|
stackView.axis = .vertical
|
|
|
|
addArrangedSubview(stackView)
|
|
}
|
|
}
|
|
|
|
@objc func buttonPressed(_ sender: Any) {
|
|
selection?((sender as? UIButton)?.tag ?? -1)
|
|
}
|
|
}
|