diff options
| author | mojganii <mojgan.jelodar@codic.se> | 2024-10-22 09:59:02 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2024-10-22 10:55:47 +0200 |
| commit | e4af7d9dd31434459baaff0b28f9e9364cf04c0f (patch) | |
| tree | 99b4b96e18238bb44e857fdd62deda809b96ff15 | |
| parent | a1c6a764418118fc3304c8c8a9b12affc07b3632 (diff) | |
| download | mullvadvpn-e4af7d9dd31434459baaff0b28f9e9364cf04c0f.tar.xz mullvadvpn-e4af7d9dd31434459baaff0b28f9e9364cf04c0f.zip | |
Fix alpha button override issues in configuration
| -rw-r--r-- | ios/MullvadVPN/Extensions/UIImage+Helpers.swift | 6 | ||||
| -rw-r--r-- | ios/MullvadVPN/Views/AppButton.swift | 13 | ||||
| -rw-r--r-- | ios/MullvadVPN/Views/CustomButton.swift | 2 |
3 files changed, 17 insertions, 4 deletions
diff --git a/ios/MullvadVPN/Extensions/UIImage+Helpers.swift b/ios/MullvadVPN/Extensions/UIImage+Helpers.swift index ebf11ea270..90d9bc7f88 100644 --- a/ios/MullvadVPN/Extensions/UIImage+Helpers.swift +++ b/ios/MullvadVPN/Extensions/UIImage+Helpers.swift @@ -26,4 +26,10 @@ extension UIImage { return resizedImage.withRenderingMode(renderingMode) } + + func withAlpha(_ alpha: CGFloat) -> UIImage? { + return UIGraphicsImageRenderer(size: size, format: imageRendererFormat).image { _ in + draw(in: CGRect(origin: .zero, size: size), blendMode: .normal, alpha: alpha) + } + } } diff --git a/ios/MullvadVPN/Views/AppButton.swift b/ios/MullvadVPN/Views/AppButton.swift index 0ce8de9a47..022bd97b13 100644 --- a/ios/MullvadVPN/Views/AppButton.swift +++ b/ios/MullvadVPN/Views/AppButton.swift @@ -119,9 +119,10 @@ class AppButton: CustomButton { return updatedAttributeContainer } - let configurationHandler: UIButton.ConfigurationUpdateHandler = { button in - button.alpha = !button.isEnabled ? 0.5 : 1.0 + let configurationHandler: UIButton.ConfigurationUpdateHandler = { [weak self] button in + guard let self else { return } button.configuration?.baseForegroundColor = button.state.customButtonTitleColor + updateButtonBackground() } configuration = config configurationUpdateHandler = configurationHandler @@ -129,6 +130,12 @@ class AppButton: CustomButton { /// Set background image based on current style. private func updateButtonBackground() { - configuration?.background.image = style.backgroundImage + if isEnabled { + // Load the normal image and set it as the background + configuration?.background.image = style.backgroundImage + } else { + // Adjust the image for the disabled state + configuration?.background.image = style.backgroundImage.withAlpha(0.5) + } } } diff --git a/ios/MullvadVPN/Views/CustomButton.swift b/ios/MullvadVPN/Views/CustomButton.swift index 8c99ddb2cc..a956025f28 100644 --- a/ios/MullvadVPN/Views/CustomButton.swift +++ b/ios/MullvadVPN/Views/CustomButton.swift @@ -14,7 +14,7 @@ extension UIControl.State { case .normal: return UIColor.AppButton.normalTitleColor case .disabled: - return UIColor.AppButton.disabledTitleColor + return UIColor.AppButton.disabledTitleColor.withAlphaComponent(0.5) case .highlighted: return UIColor.AppButton.highlightedTitleColor default: |
