diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-11-17 12:22:47 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-11-22 10:42:58 +0100 |
| commit | 3562cc5fa576c68b76a5ad85f6a3e563c7efaf6a (patch) | |
| tree | 4e54641a9978bfdaec5c3c60292eee3ed0053f16 | |
| parent | 1e3f995a7aeb3a38cf031832744e48408ceff119 (diff) | |
| download | mullvadvpn-3562cc5fa576c68b76a5ad85f6a3e563c7efaf6a.tar.xz mullvadvpn-3562cc5fa576c68b76a5ad85f6a3e563c7efaf6a.zip | |
Backport UIImage.withTintColor
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 4 | ||||
| -rw-r--r-- | ios/MullvadVPN/UIImage+TintColor.swift | 34 |
2 files changed, 38 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index c8c259d5ae..8ddd24c52d 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -113,6 +113,7 @@ 5850368D25A49E2200A43E93 /* PrivateKeyWithMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C6B35322BB87C4003C19AD /* PrivateKeyWithMetadata.swift */; }; 58561C99239A5D1500BD6B5E /* IPEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58561C98239A5D1500BD6B5E /* IPEndpoint.swift */; }; 58561C9A239A5D1500BD6B5E /* IPEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58561C98239A5D1500BD6B5E /* IPEndpoint.swift */; }; + 5856D13727450A8A00DFD627 /* UIImage+TintColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5856D13627450A8A00DFD627 /* UIImage+TintColor.swift */; }; 5857F23024C843ED00CF6F47 /* ChainedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58F840B12464491D0044E708 /* ChainedError.swift */; }; 5857F23424C8443700CF6F47 /* AsyncOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E973DD24850EB600096F90 /* AsyncOperation.swift */; }; 5857F23824C8446700CF6F47 /* AsyncBlockOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 580EE22324B3243100F9D8A1 /* AsyncBlockOperation.swift */; }; @@ -413,6 +414,7 @@ 584D26C5270C8741004EA533 /* SettingsDNSTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsDNSTextCell.swift; sourceTree = "<group>"; }; 5850366725A47AC700A43E93 /* IPAddressRange+Codable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "IPAddressRange+Codable.swift"; sourceTree = "<group>"; }; 58561C98239A5D1500BD6B5E /* IPEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPEndpoint.swift; sourceTree = "<group>"; }; + 5856D13627450A8A00DFD627 /* UIImage+TintColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+TintColor.swift"; sourceTree = "<group>"; }; 5857F24224C8662600CF6F47 /* SelectLocationHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationHeaderView.swift; sourceTree = "<group>"; }; 5857F24624C882D700CF6F47 /* SelectLocationNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationNavigationController.swift; sourceTree = "<group>"; }; 585CA70E25F8C44600B47C62 /* UIMetrics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIMetrics.swift; sourceTree = "<group>"; }; @@ -910,6 +912,7 @@ 5891BF5025E66B1E006D6FB0 /* UIBarButtonItem+KeyboardNavigation.swift */, 587CBFE222807F530028DED3 /* UIColor+Helpers.swift */, 58CCA0152242560B004F3011 /* UIColor+Palette.swift */, + 5856D13627450A8A00DFD627 /* UIImage+TintColor.swift */, 585CA70E25F8C44600B47C62 /* UIMetrics.swift */, 58FD5BF12424F7D700112C88 /* UserInterfaceInteractionRestriction.swift */, 58B8743122B25A7600015324 /* WireguardAssociatedAddresses.swift */, @@ -1327,6 +1330,7 @@ 5846227326E22A160035F7C2 /* AppStorePaymentObserver.swift in Sources */, 58FAEDEF245069C700CB0F5B /* KeychainAttributes.swift in Sources */, 585DA87A26B024F900B8C587 /* RelayCacheError.swift in Sources */, + 5856D13727450A8A00DFD627 /* UIImage+TintColor.swift in Sources */, 58CB0EE024B86751001EF0D8 /* RESTClient.swift in Sources */, 5846226A26E0E6FA0035F7C2 /* ReceiptRefreshOperation.swift in Sources */, 58293FB125124117005D0BB5 /* CustomTextField.swift in Sources */, diff --git a/ios/MullvadVPN/UIImage+TintColor.swift b/ios/MullvadVPN/UIImage+TintColor.swift new file mode 100644 index 0000000000..b8b7dd1731 --- /dev/null +++ b/ios/MullvadVPN/UIImage+TintColor.swift @@ -0,0 +1,34 @@ +// +// UIImage+TintColor.swift +// MullvadVPN +// +// Created by pronebird on 17/11/2021. +// Copyright © 2021 Mullvad VPN AB. All rights reserved. +// + +import UIKit + +extension UIImage { + + func backport_withTintColor(_ tintColor: UIColor) -> UIImage { + return backport_withTintColor(tintColor, renderingMode: renderingMode) + } + + func backport_withTintColor(_ tintColor: UIColor, renderingMode: RenderingMode) -> UIImage { + if #available(iOS 13, *) { + return withTintColor(tintColor, renderingMode: renderingMode) + } + + let rect = CGRect(origin: .zero, size: size) + let renderer = UIGraphicsImageRenderer(size: size) + + let renderedImage = renderer.image { context in + tintColor.setFill() + context.fill(rect) + draw(in: rect, blendMode: .destinationIn, alpha: 1) + } + + return renderedImage.withRenderingMode(renderingMode) + } + +} |
