mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Add letters to dialpad buttons
This commit is contained in:
@@ -19,8 +19,25 @@ import UIKit
|
||||
/// Digit button class for Dialpad screen
|
||||
class DialpadButton: UIButton {
|
||||
|
||||
struct ViewData {
|
||||
var title: String
|
||||
var subtitle: String?
|
||||
var showsSubtitleSpace: Bool
|
||||
|
||||
init(title: String, subtitle: String? = nil, showsSubtitleSpace: Bool = false) {
|
||||
self.title = title
|
||||
self.subtitle = subtitle
|
||||
self.showsSubtitleSpace = showsSubtitleSpace
|
||||
}
|
||||
}
|
||||
|
||||
private var viewData: ViewData?
|
||||
private var theme: Theme = ThemeService.shared().theme
|
||||
|
||||
private enum Constants {
|
||||
static let size: CGSize = CGSize(width: 68, height: 68)
|
||||
static let titleFont: UIFont = .boldSystemFont(ofSize: 32)
|
||||
static let subtitleFont: UIFont = .boldSystemFont(ofSize: 12)
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -40,6 +57,31 @@ class DialpadButton: UIButton {
|
||||
private func setup() {
|
||||
clipsToBounds = true
|
||||
layer.cornerRadius = Constants.size.width/2
|
||||
vc_enableMultiLinesTitle()
|
||||
}
|
||||
|
||||
func render(withViewData viewData: ViewData) {
|
||||
self.viewData = viewData
|
||||
|
||||
let totalAttributedString = NSMutableAttributedString(string: viewData.title,
|
||||
attributes: [
|
||||
.font: Constants.titleFont,
|
||||
.foregroundColor: theme.textPrimaryColor
|
||||
])
|
||||
|
||||
if let subtitle = viewData.subtitle {
|
||||
totalAttributedString.append(NSAttributedString(string: "\n" + subtitle, attributes: [
|
||||
.font: Constants.subtitleFont,
|
||||
.foregroundColor: theme.textPrimaryColor
|
||||
]))
|
||||
} else if viewData.showsSubtitleSpace {
|
||||
totalAttributedString.append(NSAttributedString(string: "\n ", attributes: [
|
||||
.font: Constants.subtitleFont,
|
||||
.foregroundColor: theme.textPrimaryColor
|
||||
]))
|
||||
}
|
||||
|
||||
setAttributedTitle(totalAttributedString, for: .normal)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,8 +91,14 @@ class DialpadButton: UIButton {
|
||||
extension DialpadButton: Themable {
|
||||
|
||||
func update(theme: Theme) {
|
||||
setTitleColor(theme.textPrimaryColor, for: .normal)
|
||||
self.theme = theme
|
||||
|
||||
backgroundColor = theme.headerBackgroundColor
|
||||
|
||||
// re-render view data if set
|
||||
if let viewData = self.viewData {
|
||||
render(withViewData: viewData)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user