Skip to content

Commit 49bd397

Browse files
Merge pull request #93 from componentskit/fix-button-image-color
set tint color for button's image
2 parents 46e859b + 198cbb8 commit 49bd397

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-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: 24 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,20 @@ 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
110+
imageView.isUserInteractionEnabled = true
96111
return imageView
97112
}
98113

99114
func updateUIView(_ imageView: UIImageView, context: Context) {
100115
imageView.image = self.image
116+
imageView.tintColor = self.tintColor
101117
}
102118
}
103119

Sources/ComponentsKit/Components/Button/UKButton.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ 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
254+
imageView.isUserInteractionEnabled = true
253255
}
254256
}
255257
}

0 commit comments

Comments
 (0)