import SwiftUI
struct ContentView: View {
var body: some View {
HStack {
VStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.red)
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.green)
}
VStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.blue)
}
}
.frame(height: 200)
.padding()
}
}
#Preview {
ContentView()
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
What code is causing the error? What version of Xcode are you using? What version of which OS are you building for?
Topic:
Programming Languages
SubTopic:
Swift
Tags:
No, that's not the best way to do what you want.
The reason you got "Hello World!" with a red background is because of this:
Text("Hello, World!")
.background(RoundedRectangle(cornerRadius: 25.0).fill(Color.red))
You applied the .background modifier to the Text item, so just the text was given the red background.
What you want to do is use a ZStack. Just like HStack is a horizontal stack and VStack is a stack along the vertical axis, a ZStack is a stack along the z-axis.
Put a rectangle inside the ZStack and it will become the background, then you layer your content on top, i.e.:
struct DashboardView: View {
var body: some View {
HStack {
VStack {
VStack {
ZStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.red)
Text("Text 1")
}
}
VStack {
ZStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.green)
Text("Text 2")
}
}
}
VStack {
ZStack {
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.blue)
VStack {
Spacer()
Text("Text 3")
Spacer()
Text("Text 4")
Spacer()
}
}
}
}
.foregroundStyle(.white)
.frame(height: 200)
.padding()
}
}
The ordering is important, for both content and modifiers. If you reverse the RoundedRectangle(...) and Text you won't see the text because the rectangle is in front of it, i.e.:
Text("Text 1")
RoundedRectangle(cornerRadius: 25.0)
.fill(Color.red)
By the way, .foregroundColor() is deprecated. While it works now, it will be removed in a later version of the OS, so you should move to the new foregroundStyle() modifier instead.
Also note that if all your text inside those rectangles is going to be the same colour, you can add that modifier to the top-level HStack, as I have done above.
There is an issue with Screen Time in the iOS 18 betas.
Please raise bugs with Apple - and not in these forums. The Developer Forums aren't really the right place to raise bugs in a new version of an OS. Apple's engineers aren't reading through these pages to see if anyone's found a bug.
These forums are for third-party developers writing apps for Apple's platforms to discuss issues with their code.
You need to raise each issue you find separately at https://www.apple.com/feedback/ You can post the FB numbers here if you want, so that others can link to them.
Others have already raised this particular issue, but your report might contain the pertinent information that will help Apple fix the bug.
Topic:
Accessibility & Inclusion
SubTopic:
General
Please raise bugs with Apple - and not in these forums. The Developer Forums aren't really the right place to raise bugs in a new version of an OS. Apple's engineers aren't reading through these pages to see if anyone's found a bug.
These forums are for third-party developers writing apps for Apple's platforms to discuss issues with their code.
You need to raise each issue you find separately at https://www.apple.com/feedback/ You can post the FB numbers here if you want, so that others can link to them.
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Have you raised a Feedback report? If not, please do so at https://www.apple.com/feedback/ then post the FB number here.
Topic:
Safari & Web
SubTopic:
General
Tags:
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding. These forums have nothing to do with product support.
I'd suggest you ask it over at the Apple Support Forums. or contact the manufacturer of the screen protector. We can't help you here. Thanks.
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Tags:
The Developer Forums aren't really the right place to raise bugs in a new version of an OS. Apple's engineers aren't reading through these pages to see if anyone's found a bug.
These forums are for third-party developers writing apps for Apple's platforms to discuss issues with their code.
You need to raise each issue you find separately at https://www.apple.com/feedback/ You can post the FB numbers here if you want, so that others can link to them.
Topic:
Accessibility & Inclusion
SubTopic:
General
Can't help you unless you explain what you were trying to put into the form.
When you say, "It didn't work", why didn't it work? What was the error message? We need the info.
Topic:
Developer Tools & Services
SubTopic:
Developer Forums
No.
Where did you see this?
Also, please don't use random tags when creating a post. This has nothing to do with Watch Connectivity.
Topic:
App & System Services
SubTopic:
General
Tags:
It's a beta. There are a number of system processes and diagnostics processes running that aren't present in a released (non-beta) OS.
I wouldn't install a beta on your primary device.
If it's not good for you, uninstall it and go back to the latest version of iOS 17.
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Tags:
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding their own apps.
Your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums. Thanks.
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Tags:
Is this on the iOS 18 beta, or is it something to do with an app that you're developing? If neither, your question is more of a product support one, so I'd suggest you ask it over at the Apple Support Forums.
These are the Developer Forums, where developers of apps for Apple's platforms ask each other for hints and tips on coding their own apps.
If it's on the betas, can you show us a screenshot of what you're entering?
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program
Tags:
Have you raised a Feedback report? If not, please do so at https://www.apple.com/feedback/ then post the FB number here.
Topic:
Community
SubTopic:
Apple Developers
Tags:
Have you raised a Feedback report? If not, please do so at https://www.apple.com/feedback/ then post the FB number here.
Topic:
Developer Tools & Services
SubTopic:
Apple Developer Program