Advertisement
Milotronik

cardView

Aug 8th, 2024
31
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct PagingCardView: View {
  4. let items: [String]
  5. @State private var currentIndex = 0
  6.  
  7. var body: some View {
  8. TabView(selection: $currentIndex) {
  9. ForEach(0..<items.count, id: \.self) { index in
  10. CardView(text: items[index])
  11. .tag(index)
  12. }
  13. }
  14. .tabViewStyle(PageTabViewStyle())
  15. .frame(height: 200)
  16. .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
  17. }
  18. }
  19.  
  20. struct CardView: View {
  21. let text: String
  22.  
  23. var body: some View {
  24. VStack {
  25. Text(text)
  26. .font(.title)
  27. .padding()
  28. .background(Color.blue)
  29. .cornerRadius(10)
  30. .foregroundColor(.white)
  31. }
  32. .frame(maxWidth: .infinity, maxHeight: .infinity)
  33. .background(Color.gray.opacity(0.2))
  34. .cornerRadius(10)
  35. .padding()
  36. }
  37. }
  38.  
  39. struct ContentView: View {
  40. var body: some View {
  41. PagingCardView(items: ["Card 1", "Card 2", "Card 3"])
  42. }
  43. }
  44.  
  45. @main
  46. struct MyApp: App {
  47. var body: some Scene {
  48. WindowGroup {
  49. ContentView()
  50. }
  51. }
  52. }
  53.  
Advertisement
Comments
  • Milotronik
    102 days
    # text 1.21 KB | 0 0
    1. import SwiftUI
    2.  
    3. struct PagingCardView: View {
    4. let items: [String]
    5. @State private var currentIndex = 0
    6.  
    7. var body: some View {
    8. TabView(selection: $currentIndex) {
    9. ForEach(0..<items.count, id: \.self) { index in
    10. CardView(text: items[index])
    11. .tag(index)
    12. }
    13. }
    14. .tabViewStyle(PageTabViewStyle())
    15. .frame(height: 200)
    16. .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
    17. }
    18. }
    19.  
    20. struct CardView: View {
    21. let text: String
    22.  
    23. var body: some View {
    24. VStack {
    25. Text(text)
    26. .font(.title)
    27. .padding()
    28. .background(Color.blue)
    29. .cornerRadius(10)
    30. .foregroundColor(.white)
    31. }
    32. .frame(maxWidth: .infinity, maxHeight: .infinity)
    33. .background(Color.gray.opacity(0.2))
    34. .cornerRadius(10)
    35. .padding()
    36. }
    37. }
    38.  
    39. struct ContentView: View {
    40. var body: some View {
    41. PagingCardView(items: ["Card 1", "Card 2", "Card 3"])
    42. }
    43. }
    44.  
    45. @main
    46. struct MyApp: App {
    47. var body: some Scene {
    48. WindowGroup {
    49. ContentView()
    50. }
    51. }
    52. }
    53.  
Add Comment
Please, Sign In to add comment
Advertisement