Signal-iOS/Signal/Registration/UserInterface/RegistrationChoiceButton.swift
2025-04-01 18:02:18 -05:00

90 lines
2.8 KiB
Swift

//
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
import Foundation
import SignalUI
class RegistrationChoiceButton: OWSFlatButton
{
init(
title: String,
body: String,
iconName: String
) {
super.init()
setBackgroundColors(upColor: Theme.isDarkThemeEnabled ? .ows_gray80 : .ows_gray02)
layer.cornerRadius = 8
clipsToBounds = true
// Icon
let iconContainer = UIView()
let iconView = UIImageView(image: UIImage(named: iconName))
iconView.contentMode = .scaleAspectFit
iconContainer.addSubview(iconView)
iconView.autoPinWidthToSuperview()
iconView.autoSetDimensions(to: CGSize(square: 48))
iconView.autoVCenterInSuperview()
iconView.autoMatch(.height, to: .height, of: iconContainer, withOffset: 0, relation: .lessThanOrEqual)
// Labels
let titleLabel = UILabel()
titleLabel.text = title
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.font = UIFont.dynamicTypeBody.semibold()
titleLabel.textColor = Theme.primaryTextColor
let bodyLabel = UILabel()
bodyLabel.text = body
bodyLabel.numberOfLines = 0
bodyLabel.lineBreakMode = .byWordWrapping
bodyLabel.font = .dynamicTypeBody2
bodyLabel.textColor = Theme.secondaryTextAndIconColor
let topSpacer = UIView.vStretchingSpacer()
let bottomSpacer = UIView.vStretchingSpacer()
let vStack = UIStackView(arrangedSubviews: [
topSpacer,
titleLabel,
bodyLabel,
bottomSpacer
])
vStack.axis = .vertical
vStack.spacing = 8
topSpacer.autoMatch(.height, to: .height, of: bottomSpacer)
// Disclosure Indicator
let disclosureContainer = UIView()
let disclosureView = UIImageView()
disclosureView.setTemplateImage(
UIImage(imageLiteralResourceName: "chevron-right-20"),
tintColor: Theme.secondaryTextAndIconColor
)
disclosureView.contentMode = .scaleAspectFit
disclosureContainer.addSubview(disclosureView)
disclosureView.autoPinEdgesToSuperviewEdges()
disclosureView.autoSetDimension(.width, toSize: 20)
let hStack = UIStackView(arrangedSubviews: [
iconContainer,
vStack,
disclosureContainer
])
hStack.axis = .horizontal
hStack.spacing = 16
hStack.isLayoutMarginsRelativeArrangement = true
hStack.layoutMargins = UIEdgeInsets(top: 24, leading: 16, bottom: 24, trailing: 16)
hStack.isUserInteractionEnabled = false
addSubview(hStack)
hStack.autoPinEdgesToSuperviewEdges()
}
}