From 02030be3c2f434e54d415567a046649b8711e9d5 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 7 May 2025 13:22:48 +0300 Subject: [PATCH 1/2] set tint color for button's image --- .../avatar_placeholder.imageset/Contents.json | 3 ++ .../Components/Avatar/Models/AvatarVM.swift | 2 +- .../Components/Button/SUButton.swift | 31 ++++++++++++++----- .../Components/Button/UKButton.swift | 1 + 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Examples/DemosApp/DemosApp/Assets.xcassets/avatar_placeholder.imageset/Contents.json b/Examples/DemosApp/DemosApp/Assets.xcassets/avatar_placeholder.imageset/Contents.json index 68cb3fb8..1b231c57 100644 --- a/Examples/DemosApp/DemosApp/Assets.xcassets/avatar_placeholder.imageset/Contents.json +++ b/Examples/DemosApp/DemosApp/Assets.xcassets/avatar_placeholder.imageset/Contents.json @@ -17,5 +17,8 @@ "info" : { "author" : "xcode", "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" } } diff --git a/Sources/ComponentsKit/Components/Avatar/Models/AvatarVM.swift b/Sources/ComponentsKit/Components/Avatar/Models/AvatarVM.swift index 2d7418b0..b946e1ed 100644 --- a/Sources/ComponentsKit/Components/Avatar/Models/AvatarVM.swift +++ b/Sources/ComponentsKit/Components/Avatar/Models/AvatarVM.swift @@ -95,7 +95,7 @@ extension AvatarVM { self.placeholderBackgroundColor.setFill() UIBezierPath(rect: CGRect(origin: .zero, size: size)).fill() - icon?.withTintColor(self.placeholderForegroundColor, renderingMode: .alwaysOriginal).draw(in: CGRect( + icon?.withTintColor(self.placeholderForegroundColor).draw(in: CGRect( x: (size.width - iconSize.width) / 2, y: (size.height - iconSize.height) / 2, width: iconSize.width, diff --git a/Sources/ComponentsKit/Components/Button/SUButton.swift b/Sources/ComponentsKit/Components/Button/SUButton.swift index 80cf0e89..10b39db9 100644 --- a/Sources/ComponentsKit/Components/Button/SUButton.swift +++ b/Sources/ComponentsKit/Components/Button/SUButton.swift @@ -59,19 +59,31 @@ public struct SUButton: View { SULoading(model: self.model.preferredLoadingVM) Text(self.model.title) case (false, let uiImage?, .leading) where self.model.title.isEmpty: - ButtonImageView(image: uiImage) - .frame(width: self.model.imageSide, height: self.model.imageSide) + ButtonImageView( + image: uiImage, + tintColor: self.model.foregroundColor.uiColor + ) + .frame(width: self.model.imageSide, height: self.model.imageSide) case (false, let uiImage?, .leading): - ButtonImageView(image: uiImage) - .frame(width: self.model.imageSide, height: self.model.imageSide) + ButtonImageView( + image: uiImage, + tintColor: self.model.foregroundColor.uiColor + ) + .frame(width: self.model.imageSide, height: self.model.imageSide) Text(self.model.title) case (false, let uiImage?, .trailing) where self.model.title.isEmpty: - ButtonImageView(image: uiImage) - .frame(width: self.model.imageSide, height: self.model.imageSide) + ButtonImageView( + image: uiImage, + tintColor: self.model.foregroundColor.uiColor + ) + .frame(width: self.model.imageSide, height: self.model.imageSide) case (false, let uiImage?, .trailing): Text(self.model.title) - ButtonImageView(image: uiImage) - .frame(width: self.model.imageSide, height: self.model.imageSide) + ButtonImageView( + image: uiImage, + tintColor: self.model.foregroundColor.uiColor + ) + .frame(width: self.model.imageSide, height: self.model.imageSide) case (false, _, _): Text(self.model.title) } @@ -88,16 +100,19 @@ private struct ButtonImageView: UIViewRepresentable { } let image: UIImage + let tintColor: UIColor func makeUIView(context: Context) -> UIImageView { let imageView = InternalImageView() imageView.image = self.image + imageView.tintColor = self.tintColor imageView.contentMode = .scaleAspectFit return imageView } func updateUIView(_ imageView: UIImageView, context: Context) { imageView.image = self.image + imageView.tintColor = self.tintColor } } diff --git a/Sources/ComponentsKit/Components/Button/UKButton.swift b/Sources/ComponentsKit/Components/Button/UKButton.swift index e7b63552..a4da80a6 100644 --- a/Sources/ComponentsKit/Components/Button/UKButton.swift +++ b/Sources/ComponentsKit/Components/Button/UKButton.swift @@ -250,6 +250,7 @@ extension UKButton { imageView.image = model.image imageView.contentMode = .scaleAspectFit imageView.isHidden = model.isLoading || model.imageSrc.isNil + imageView.tintColor = model.foregroundColor.uiColor } } } From 198cbb8e8b373e31cfb49a2cb55451af07bf7430 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 7 May 2025 14:18:30 +0300 Subject: [PATCH 2/2] enable user interaction for images in buttons --- Sources/ComponentsKit/Components/Button/SUButton.swift | 1 + Sources/ComponentsKit/Components/Button/UKButton.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/ComponentsKit/Components/Button/SUButton.swift b/Sources/ComponentsKit/Components/Button/SUButton.swift index 10b39db9..2a4fdc3c 100644 --- a/Sources/ComponentsKit/Components/Button/SUButton.swift +++ b/Sources/ComponentsKit/Components/Button/SUButton.swift @@ -107,6 +107,7 @@ private struct ButtonImageView: UIViewRepresentable { imageView.image = self.image imageView.tintColor = self.tintColor imageView.contentMode = .scaleAspectFit + imageView.isUserInteractionEnabled = true return imageView } diff --git a/Sources/ComponentsKit/Components/Button/UKButton.swift b/Sources/ComponentsKit/Components/Button/UKButton.swift index a4da80a6..9653de56 100644 --- a/Sources/ComponentsKit/Components/Button/UKButton.swift +++ b/Sources/ComponentsKit/Components/Button/UKButton.swift @@ -251,6 +251,7 @@ extension UKButton { imageView.contentMode = .scaleAspectFit imageView.isHidden = model.isLoading || model.imageSrc.isNil imageView.tintColor = model.foregroundColor.uiColor + imageView.isUserInteractionEnabled = true } } }