diff --git a/ios/MullvadVPN/Extensions/UIImage+Helpers.swift b/ios/MullvadVPN/Extensions/UIImage+Helpers.swift index ebf11ea270a4..2c5a935a3885 100644 --- a/ios/MullvadVPN/Extensions/UIImage+Helpers.swift +++ b/ios/MullvadVPN/Extensions/UIImage+Helpers.swift @@ -26,4 +26,23 @@ extension UIImage { return resizedImage.withRenderingMode(renderingMode) } + + func withAlpha(_ alpha: CGFloat) -> UIImage? { + UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale) + guard let context = UIGraphicsGetCurrentContext(), let cgImage = self.cgImage else { return nil } + + let rect = CGRect(origin: .zero, size: self.size) + + context.scaleBy(x: 1.0, y: -1.0) // Flip vertically + context.translateBy(x: 0, y: -rect.size.height) + + context.setBlendMode(.normal) + context.setAlpha(alpha) // Set the alpha + context.draw(cgImage, in: rect) + + let newImage = UIGraphicsGetImageFromCurrentImageContext() + UIGraphicsEndImageContext() + + return newImage + } } diff --git a/ios/MullvadVPN/Views/AppButton.swift b/ios/MullvadVPN/Views/AppButton.swift index 0ce8de9a47e1..022bd97b130b 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 8c99ddb2cc6c..a956025f28e2 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: