tab Function - leider fehlerhaft
This commit is contained in:
parent
077a0f183c
commit
418e627457
6 changed files with 43 additions and 5 deletions
|
|
@ -4,6 +4,10 @@ import SwiftUI
|
||||||
|
|
||||||
|
|
||||||
struct BikeView: View {
|
struct BikeView: View {
|
||||||
|
static var title = "Bike"
|
||||||
|
static var image = "bicycle"
|
||||||
|
|
||||||
|
|
||||||
var bike = Bike(name: "Fahrrad", price: 11.31, color: Color.cyan)
|
var bike = Bike(name: "Fahrrad", price: 11.31, color: Color.cyan)
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack{
|
VStack{
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,35 @@ enum TabLabel: String {
|
||||||
case trains
|
case trains
|
||||||
case cars
|
case cars
|
||||||
var title: String { rawValue.capitalized }
|
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 {
|
struct ContentView: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TabView {
|
TabView {
|
||||||
Tab(TabLabel.bikes.title, systemImage: "bicycle") {
|
Tab(TabLabel.bikes.title, systemImage: TabLabel.bikes.image) {
|
||||||
BikeView()
|
BikeView()
|
||||||
}
|
}
|
||||||
Tab(TabLabel.bikes.title, systemImage: "train.side.front.car") {
|
Tab(TabLabel.bikes.title, systemImage: TabLabel.trains.image) {
|
||||||
TrainView()
|
TrainView()
|
||||||
}
|
}
|
||||||
Tab("drücken", systemImage: "car") {
|
Tab("drücken", systemImage: TabLabel.cars.image) {
|
||||||
SwapperView()
|
SwapperView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
Models.swift
12
Models.swift
|
|
@ -6,6 +6,18 @@ protocol Vehicle {
|
||||||
var name: String { get }
|
var name: String { get }
|
||||||
var color: Color { get set }
|
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 {
|
struct Train: Vehicle, CustomStringConvertible , CustomLocalizedStringResourceConvertible {
|
||||||
var name: String
|
var name: String
|
||||||
var color: Color
|
var color: Color
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct SwapperView: View{
|
struct SwapperView: View{
|
||||||
|
static var title = "Swap"
|
||||||
|
static var image = "rectangle.2.swap"
|
||||||
|
|
||||||
|
|
||||||
@State var sw = Swapper(a: "Apfel", b: "Banana")
|
@State var sw = Swapper(a: "Apfel", b: "Banana")
|
||||||
@State var a = "Apfel"
|
@State var a = "Apfel"
|
||||||
@State var b = "Banane"
|
@State var b = "Banane"
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -3,7 +3,10 @@
|
||||||
import SwiftUI
|
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 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)}
|
var train2 = Train(name: "RE1423", delay: 1){ Bike(name: "Bulls", price: 1.90, color: Color.red)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue