Skip to content
Snippets Groups Projects
SegmentedControlButton.swift 1.04 KiB
Newer Older
Bruno Muniz's avatar
Bruno Muniz committed
import UIKit
import Shared

final class SegmentedControlButton: UIControl {
Ahmed Shehata's avatar
Ahmed Shehata committed
    private let titleLabel = UILabel()
    private let imageView = UIImageView()
Bruno Muniz's avatar
Bruno Muniz committed

    init() {
        super.init(frame: .zero)

Ahmed Shehata's avatar
Ahmed Shehata committed
        titleLabel.textAlignment = .center
        titleLabel.textColor = Asset.neutralWhite.color
        titleLabel.font = Fonts.Mulish.semiBold.font(size: 13.0)
Bruno Muniz's avatar
Bruno Muniz committed

Ahmed Shehata's avatar
Ahmed Shehata committed
        addSubview(titleLabel)
        addSubview(imageView)
Bruno Muniz's avatar
Bruno Muniz committed

Ahmed Shehata's avatar
Ahmed Shehata committed
        imageView.snp.makeConstraints {
            $0.top.equalToSuperview().offset(7.5)
            $0.centerX.equalToSuperview()
        }
Bruno Muniz's avatar
Bruno Muniz committed

Ahmed Shehata's avatar
Ahmed Shehata committed
        titleLabel.snp.makeConstraints {
            $0.top.equalTo(imageView.snp.bottom).offset(2)
            $0.centerX.equalToSuperview()
            $0.bottom.equalToSuperview().offset(-7.5)
        }
Bruno Muniz's avatar
Bruno Muniz committed
    }

    required init?(coder: NSCoder) { nil }
Ahmed Shehata's avatar
Ahmed Shehata committed

    func setup(title: String, icon: UIImage) {
        titleLabel.text = title
        imageView.image = icon
    }

    func update(color: UIColor) {
        imageView.tintColor = color
        titleLabel.textColor = color
    }
Bruno Muniz's avatar
Bruno Muniz committed
}