|
|
|
Have you ever had a maths problem where the instructor poses a verbose word problem?
The important skill was tossing out misleading data points, and focusing on the problem's main point. This is what your code felt like when I tried to understand your question! Most of your code has nothing to do with the SwiftUI issue. (A-hem!) What I think you're attempting is a gradual blending from the top of your screen to the toolbar at the bottom. Hard to tell; this was my best guess. Please watch this updated video (23 Oct 2021). What is behind the main SwiftUI view? In a nutshell, Paul answers your question. You ask: Why does my Linear Gradient have a solid (white/black) background behind it? Paul's answer: It doesn't. (Watch the video for details.) But your screenshot clearly shows, uh, white! You need to understand what's happening. I copied your code into Playground and tossed all the references to Winterfest trees, coal, and other unnecessary cruft. So the biggest clue was your observation of the white/black background behind your linear gradient. Those are the defaults for light and dark mode. So the next question then might be WHY are you seeing these? And why behind your Linear Gradient? Take a look at your gradient's modifiers. Hey! There's an offset there! You need to remember that SwiftUI draws the gradient in place, then PUSHES in the offset direction. In your code, it pushes it towards the top of the screen, but the gradient's frame remains in its original location. It leaves behind what? An empty space where the default background shines through. But as @twostraws warns in his video, do not try to muck with what's behind your views. Instead, how do you adjust what you have on screen? I played around with this for a bit and developed a solution for you to try in Playgrounds. Copy / Paste into Playgrounds. The TestPadding struct has a withPadding constant. Without padding, you'll see how the gradient is pushed up, and the background shows through revealing the cause of your frustration. Change the withPadding constant to true, and see the results. Maybe this is what you're looking for?
|
|
Not exactly what I was looking for, but I think you lead me to my desired solution? Will update. Also, I understand why this didn't make a whole lot of sense without more context. |
SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.