Advertisement
QwertyAvatar

Untitled

Apr 4th, 2023
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.81 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4.     @State var textColor = Color.black
  5.    
  6.     var body: some View {
  7.         NavigationView {
  8.             VStack {
  9.                 Text("Witaj w mojej aplikacji!")
  10.                     .foregroundColor(textColor)
  11.                 NavigationLink(
  12.                     destination: ColorSelectionView(textColor: $textColor),
  13.                     label: {
  14.                         Text("Wybierz kolor")
  15.                             .foregroundColor(.white)
  16.                             .padding()
  17.                             .background(Color.blue)
  18.                             .cornerRadius(10)
  19.                     })
  20.             }
  21.             .navigationTitle("Aplikacja z kolorem")
  22.         }
  23.     }
  24. }
  25.  
  26. struct ColorSelectionView: View {
  27.     @Binding var textColor: Color
  28.    
  29.     var body: some View {
  30.         VStack {
  31.             Text("Wybierz kolor tekstu:")
  32.             HStack {
  33.                 ColorBox(color: .red, textColor: $textColor)
  34.                 ColorBox(color: .green, textColor: $textColor)
  35.             }
  36.             HStack {
  37.                 ColorBox(color: .blue, textColor: $textColor)
  38.                 ColorBox(color: .yellow, textColor: $textColor)
  39.             }
  40.         }
  41.         .navigationTitle("Wybór koloru")
  42.     }
  43. }
  44.  
  45. struct ColorBox: View {
  46.     let color: Color
  47.     @Binding var textColor: Color
  48.    
  49.     var body: some View {
  50.         Button(action: {
  51.             textColor = color
  52.         }, label: {
  53.             RoundedRectangle(cornerRadius: 10)
  54.                 .fill(color)
  55.                 .frame(width: 50, height: 50)
  56.                 .overlay(
  57.                     RoundedRectangle(cornerRadius: 10)
  58.                         .stroke(textColor == color ? Color.white : Color.clear, lineWidth: 4)
  59.                 )
  60.         })
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement