Skip to content

Instantly share code, notes, and snippets.

@sujinnaljin
Created July 6, 2022 12:56
Show Gist options
  • Save sujinnaljin/e06699969cb82500ed3a41fdf3b64d4f to your computer and use it in GitHub Desktop.
Save sujinnaljin/e06699969cb82500ed3a41fdf3b64d4f to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var firstTitle = "firstTitle"
@State var secondTitle = "secondTitle"
@State var thirdTitle = "thirdTitle"
var body: some View {
VStack {
Text(firstTitle)
.background(.random)
Text(secondTitle)
.background(.random)
Text(thirdTitle)
.background(.random)
Button("Change first title") {
firstTitle = "hello world"
}
}
}
}
extension ShapeStyle where Self == Color {
static var random: Color {
Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment