I want to create a gradient color for my widget using custom colors. And I have a problem when I only use two colors, as a result, not one of the colors is applied, but the background turns green!
struct WeatherWidgetMediumView: View {
var gradient: LinearGradient {
LinearGradient(
gradient: Gradient(
colors:
[
Color(red: 96.0/255.0, green: 171.0/255.0, blue: 239.0/255.0),
Color(red: 163.0/255.0, green: 230.0/255.0, blue: 244.0/255.0)
]),
startPoint: .top,
endPoint: .bottom)
}
var body: some View {
GeometryReader { geo in
HStack(alignment: .center) {
Divider().background(Color.black).padding(.vertical, 16.0).opacity(0.1)
}
}
.background(gradient)
}
}
But If I added one more color it's looks great.
struct WeatherWidgetMediumView: View {
let weather: Weather
var gradient: LinearGradient {
LinearGradient(
gradient: Gradient(
colors:
[
Color(red: 96.0/255.0, green: 171.0/255.0, blue: 239.0/255.0),
Color(red: 96.0/255.0, green: 171.0/255.0, blue: 239.0/255.0),
Color(red: 163.0/255.0, green: 230.0/255.0, blue: 244.0/255.0)
]),
startPoint: .top,
endPoint: .bottom)
}
var body: some View {
GeometryReader { geo in
HStack(alignment: .center) {
Divider().background(Color.black).padding(.vertical, 16.0).opacity(0.1)
}
Spacer()
}
.background(gradient)
}
}
UPD: Create a GitHub project with this issue
https://github.com/Maxim-Zakopaylov/widgetKitGradientIssue
I've faced the exact issue in my app, and I've fixed it by adding .blendMode(.darken) after the background modifier. I hope that would solve your problem too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With