Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct ContentView: View {
- @State var textColor = Color.black
- var body: some View {
- NavigationView {
- VStack {
- Text("Witaj w mojej aplikacji!")
- .foregroundColor(textColor)
- NavigationLink(
- destination: ColorSelectionView(textColor: $textColor),
- label: {
- Text("Wybierz kolor")
- .foregroundColor(.white)
- .padding()
- .background(Color.blue)
- .cornerRadius(10)
- })
- }
- .navigationTitle("Aplikacja z kolorem")
- }
- }
- }
- struct ColorSelectionView: View {
- @Binding var textColor: Color
- var body: some View {
- VStack {
- Text("Wybierz kolor tekstu:")
- HStack {
- ColorBox(color: .red, textColor: $textColor)
- ColorBox(color: .green, textColor: $textColor)
- }
- HStack {
- ColorBox(color: .blue, textColor: $textColor)
- ColorBox(color: .yellow, textColor: $textColor)
- }
- }
- .navigationTitle("Wybór koloru")
- }
- }
- struct ColorBox: View {
- let color: Color
- @Binding var textColor: Color
- var body: some View {
- Button(action: {
- textColor = color
- }, label: {
- RoundedRectangle(cornerRadius: 10)
- .fill(color)
- .frame(width: 50, height: 50)
- .overlay(
- RoundedRectangle(cornerRadius: 10)
- .stroke(textColor == color ? Color.white : Color.clear, lineWidth: 4)
- )
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement