Skip to content

Commit 02030be

Browse files
set tint color for button's image
1 parent 46e859b commit 02030be

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

Examples/DemosApp/DemosApp/Assets.xcassets/avatar_placeholder.imageset/Contents.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@
1717
"info" : {
1818
"author" : "xcode",
1919
"version" : 1
20+
},
21+
"properties" : {
22+
"template-rendering-intent" : "template"
2023
}
2124
}

Sources/ComponentsKit/Components/Avatar/Models/AvatarVM.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extension AvatarVM {
9595
self.placeholderBackgroundColor.setFill()
9696
UIBezierPath(rect: CGRect(origin: .zero, size: size)).fill()
9797

98-
icon?.withTintColor(self.placeholderForegroundColor, renderingMode: .alwaysOriginal).draw(in: CGRect(
98+
icon?.withTintColor(self.placeholderForegroundColor).draw(in: CGRect(
9999
x: (size.width - iconSize.width) / 2,
100100
y: (size.height - iconSize.height) / 2,
101101
width: iconSize.width,

Sources/ComponentsKit/Components/Button/SUButton.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,31 @@ public struct SUButton: View {
5959
SULoading(model: self.model.preferredLoadingVM)
6060
Text(self.model.title)
6161
case (false, let uiImage?, .leading) where self.model.title.isEmpty:
62-
ButtonImageView(image: uiImage)
63-
.frame(width: self.model.imageSide, height: self.model.imageSide)
62+
ButtonImageView(
63+
image: uiImage,
64+
tintColor: self.model.foregroundColor.uiColor
65+
)
66+
.frame(width: self.model.imageSide, height: self.model.imageSide)
6467
case (false, let uiImage?, .leading):
65-
ButtonImageView(image: uiImage)
66-
.frame(width: self.model.imageSide, height: self.model.imageSide)
68+
ButtonImageView(
69+
image: uiImage,
70+
tintColor: self.model.foregroundColor.uiColor
71+
)
72+
.frame(width: self.model.imageSide, height: self.model.imageSide)
6773
Text(self.model.title)
6874
case (false, let uiImage?, .trailing) where self.model.title.isEmpty:
69-
ButtonImageView(image: uiImage)
70-
.frame(width: self.model.imageSide, height: self.model.imageSide)
75+
ButtonImageView(
76+
image: uiImage,
77+
tintColor: self.model.foregroundColor.uiColor
78+
)
79+
.frame(width: self.model.imageSide, height: self.model.imageSide)
7180
case (false, let uiImage?, .trailing):
7281
Text(self.model.title)
73-
ButtonImageView(image: uiImage)
74-
.frame(width: self.model.imageSide, height: self.model.imageSide)
82+
ButtonImageView(
83+
image: uiImage,
84+
tintColor: self.model.foregroundColor.uiColor
85+
)
86+
.frame(width: self.model.imageSide, height: self.model.imageSide)
7587
case (false, _, _):
7688
Text(self.model.title)
7789
}
@@ -88,16 +100,19 @@ private struct ButtonImageView: UIViewRepresentable {
88100
}
89101

90102
let image: UIImage
103+
let tintColor: UIColor
91104

92105
func makeUIView(context: Context) -> UIImageView {
93106
let imageView = InternalImageView()
94107
imageView.image = self.image
108+
imageView.tintColor = self.tintColor
95109
imageView.contentMode = .scaleAspectFit
96110
return imageView
97111
}
98112

99113
func updateUIView(_ imageView: UIImageView, context: Context) {
100114
imageView.image = self.image
115+
imageView.tintColor = self.tintColor
101116
}
102117
}
103118

Sources/ComponentsKit/Components/Button/UKButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ extension UKButton {
250250
imageView.image = model.image
251251
imageView.contentMode = .scaleAspectFit
252252
imageView.isHidden = model.isLoading || model.imageSrc.isNil
253+
imageView.tintColor = model.foregroundColor.uiColor
253254
}
254255
}
255256
}

0 commit comments

Comments
 (0)