summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2021-04-28 17:39:07 +0200
committerAndrej Mihajlov <and@mullvad.net>2021-05-03 16:37:27 +0200
commit9adc24e7ca0c0d2e01ed25c75f8d662964a9f29c (patch)
tree54d76454355bf7751926069732892cf2843fb80f
parent6cd213fe8c9783451f38e1bccd8620a4c0e60c32 (diff)
downloadmullvadvpn-9adc24e7ca0c0d2e01ed25c75f8d662964a9f29c.tar.xz
mullvadvpn-9adc24e7ca0c0d2e01ed25c75f8d662964a9f29c.zip
LinkButton: add titleString to handle the link title
-rw-r--r--ios/MullvadVPN/AppButton.swift16
1 files changed, 7 insertions, 9 deletions
diff --git a/ios/MullvadVPN/AppButton.swift b/ios/MullvadVPN/AppButton.swift
index e0cd6eb7d9..0e12120e2e 100644
--- a/ios/MullvadVPN/AppButton.swift
+++ b/ios/MullvadVPN/AppButton.swift
@@ -62,24 +62,22 @@ private extension UIControl.State {
commonInit()
}
- override func setTitle(_ title: String?, for state: UIControl.State) {
- if let title = title {
- setAttributedTitle(makeAttributedTitle(title, for: state), for: state)
- } else {
- setAttributedTitle(nil, for: state)
+ var titleString: String? {
+ didSet {
+ updateAttributedTitle(string: titleString)
}
}
private func commonInit() {
imageAlignment = .trailing
contentHorizontalAlignment = .leading
+ }
+ private func updateAttributedTitle(string: String?) {
let states: [UIControl.State] = [.normal, .highlighted, .disabled]
states.forEach { (state) in
- if let title = self.title(for: state) {
- let attributedTitle = makeAttributedTitle(title, for: state)
- self.setAttributedTitle(attributedTitle, for: state)
- }
+ let attributedTitle = string.flatMap { makeAttributedTitle($0, for: state) }
+ self.setAttributedTitle(attributedTitle, for: state)
}
}