tab Function - leider fehlerhaft

This commit is contained in:
Ingo Rohlf 2025-10-21 15:23:06 +02:00
parent 077a0f183c
commit 418e627457
6 changed files with 43 additions and 5 deletions

View file

@ -4,6 +4,10 @@ import SwiftUI
struct BikeView: View {
static var title = "Bike"
static var image = "bicycle"
var bike = Bike(name: "Fahrrad", price: 11.31, color: Color.cyan)
var body: some View {
VStack{

View file

@ -7,19 +7,35 @@ enum TabLabel: String {
case trains
case cars
var title: String { rawValue.capitalized }
var image: String { switch self {
case .bikes:
"bicycle"
case .trains:
"train.side.front.car"
case .cars:
"hand.draw.fill"
} }
}
//
//func tab<C: TabContent>(_ contentType: C.Type)
//-> Tab<Never, C, DefaultTabLabel> {
// Tab(C.title, systemImage: C.image) {
// C()
// }
//}
struct ContentView: View {
var body: some View {
TabView {
Tab(TabLabel.bikes.title, systemImage: "bicycle") {
Tab(TabLabel.bikes.title, systemImage: TabLabel.bikes.image) {
BikeView()
}
Tab(TabLabel.bikes.title, systemImage: "train.side.front.car") {
Tab(TabLabel.bikes.title, systemImage: TabLabel.trains.image) {
TrainView()
}
Tab("drücken", systemImage: "car") {
Tab("drücken", systemImage: TabLabel.cars.image) {
SwapperView()
}
}

View file

@ -6,6 +6,18 @@ protocol Vehicle {
var name: String { get }
var color: Color { get set }
}
protocol TabContent {
init() //title: String, image: String)
// <#statements#>
// }
static var title: String { get }
static var image: String { get }
}
struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible {
var name: String
var color: Color

View file

@ -1,6 +1,9 @@
import SwiftUI
struct SwapperView: View{
static var title = "Swap"
static var image = "rectangle.2.swap"
@State var sw = Swapper(a: "Apfel", b: "Banana")
@State var a = "Apfel"

View file

@ -3,7 +3,10 @@
import SwiftUI
struct TrainView: View {
struct TrainView: View , TabContent {
static var title = "Train"
static var image = "train.side.front.car"
var train = Train(name: "RE3412", color: Color.yellow, delay: 2 ){ Bike.trek}
var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", price: 1.90, color: Color.red)}