Files
comaps/iphone/Maps/Classes/Components/VerticallyAlignedButton.swift
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

89 lines
2.0 KiB
Swift

@IBDesignable
class VerticallyAlignedButton: UIControl {
@IBInspectable
var image: UIImage? {
didSet {
imageView.image = image
}
}
@IBInspectable
var title: String? {
didSet {
if localizedText == nil {
titleLabel.text = title
}
}
}
@IBInspectable
var localizedText: String? {
didSet {
if let localizedText = localizedText {
titleLabel.text = L(localizedText)
}
}
}
@IBInspectable
var spacing: CGFloat = 4 {
didSet {
spacingConstraint.constant = spacing
}
}
@IBInspectable
var numberOfLines: Int {
get {
return titleLabel.numberOfLines
}
set {
titleLabel.numberOfLines = newValue
}
}
private lazy var spacingConstraint: NSLayoutConstraint = {
let spacingConstraint = titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: spacing)
return spacingConstraint
}()
lazy var titleLabel: UILabel = {
let titleLabel = UILabel()
titleLabel.textAlignment = .center
titleLabel.translatesAutoresizingMaskIntoConstraints = false
return titleLabel
}()
lazy var imageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
private func setupView() {
addSubview(titleLabel)
addSubview(imageView)
NSLayoutConstraint.activate([
imageView.topAnchor.constraint(equalTo: topAnchor),
imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
imageView.widthAnchor.constraint(equalTo: imageView.heightAnchor),
spacingConstraint,
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor),
titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor),
titleLabel.topAnchor.constraint(equalTo: bottomAnchor)
])
}
}