55 lines
1.9 KiB
Swift
55 lines
1.9 KiB
Swift
//
|
|
// CommonButtonMenu.swift
|
|
// Wallet
|
|
//
|
|
// Created by Igor on 04.02.2021.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class CommonButtonMenu: UIButton {
|
|
|
|
@IBInspectable var title: String? {
|
|
didSet { titleLbl.attributedText = title?.localized.attributed(style: .regular, size: 10, color: Asset.textSnow.color, alignment: .center) }
|
|
}
|
|
@IBInspectable var image: UIImage? {
|
|
didSet { imgView.image = image }
|
|
}
|
|
|
|
private let titleLbl = UILabel()
|
|
private let imgView = UIImageView()
|
|
private let contentView = UIView()
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
setBackgroundImage(.colored(Asset.deepWater.color, size: frameSize, cornerRadius: 16), for: .normal)
|
|
contentView.backgroundColor = .clear
|
|
contentView.isUserInteractionEnabled = false
|
|
addSubview(contentView)
|
|
imgView.contentMode = .scaleAspectFit
|
|
titleLbl.textAlignment = .center
|
|
titleLbl.numberOfLines = 0
|
|
contentView.addSubview(titleLbl)
|
|
if image != nil {
|
|
contentView.addSubview(imgView)
|
|
}
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
titleLbl.frameWidth = frameWidth - 8
|
|
titleLbl.sizeToFit()
|
|
let size: CGFloat = image != nil ? 24 : 0
|
|
let height: CGFloat = size + 4 + titleLbl.frameHeight
|
|
contentView.frame = CGRect(x: 0, y: (frameHeight - height)/2, width: frameWidth, height: height)
|
|
contentView.center = CGPoint(x: frameWidth/2, y: frameHeight/2)
|
|
if image != nil {
|
|
imgView.frame = CGRect(x: (frameWidth - size)/2, y: 0, width: size, height: size)
|
|
titleLbl.frame = CGRect(x: 4, y: size + 4, width: frameWidth - 8, height: titleLbl.frameHeight)
|
|
} else {
|
|
titleLbl.frame = CGRect(x: 4, y: 0, width: frameWidth - 8, height: titleLbl.frameHeight)
|
|
}
|
|
}
|
|
}
|