ListView verschiedene möglichkeiten
This commit is contained in:
parent
418e627457
commit
3e9762c3bf
8 changed files with 116 additions and 5 deletions
|
|
@ -11,10 +11,7 @@ struct TheSwiftWeek: App {
|
|||
VStack{
|
||||
|
||||
|
||||
Text(.myVehicle)
|
||||
TrainView(train: train)
|
||||
TrainView(train: train2)
|
||||
Spacer()
|
||||
CountView()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
34
CountView.swift
Normal file
34
CountView.swift
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// CountView.swift
|
||||
// TheSwiftWeek
|
||||
//
|
||||
// Created by Ingo Rohlf on 21.10.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CountView: View, TabContent {
|
||||
static var title = "Count"
|
||||
static var image = "42.circle"
|
||||
|
||||
@State var text = ""
|
||||
|
||||
var body: some View {
|
||||
TextField("Enter Emoji", text: $text)
|
||||
.padding()
|
||||
|
||||
Text("""
|
||||
Zeichenzahl: \(text.count)
|
||||
Unicode: \(text.unicodeScalars.count)
|
||||
UTF-8 Bytes: \(text.lengthOfBytes(using: .utf8))
|
||||
""")
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#Preview {
|
||||
CountView()
|
||||
}
|
||||
48
ListView.swift
Normal file
48
ListView.swift
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//
|
||||
// ListView.swift
|
||||
// TheSwiftWeek
|
||||
//
|
||||
// Created by Ingo Rohlf on 21.10.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
//import Playgrounds
|
||||
import Foundation
|
||||
|
||||
struct ListView: View , TabContent{
|
||||
static var title = "List"
|
||||
static var image = "list.bullet"
|
||||
|
||||
@State var bikes = Bike.all
|
||||
var body: some View {
|
||||
List {
|
||||
Text(bikes[0].name)
|
||||
Text(bikes[1].name)
|
||||
Text(bikes[2].name)
|
||||
}
|
||||
List(bikes, id: \.name){ bike in
|
||||
HStack {
|
||||
Color(bike.color)
|
||||
Text(String(bike.name))
|
||||
}
|
||||
}
|
||||
List(bikes, id: \.name){
|
||||
Text(String($0.price))
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//#Playground {
|
||||
// var students = ["Bill", "Linus"]
|
||||
// let size = [1.65, 1.79]
|
||||
//}
|
||||
|
||||
|
||||
#Preview {
|
||||
ListView()
|
||||
}
|
||||
|
|
@ -1,10 +1,26 @@
|
|||
{
|
||||
"sourceLanguage" : "en",
|
||||
"strings" : {
|
||||
" Zeichenzahl: %lld\n Unicode: %lld\n UTF-8 Bytes: %lld" : {
|
||||
"comment" : "A block of text showing the number of characters, Unicode scalars, and UTF-8 bytes in the text entered by the user.",
|
||||
"isCommentAutoGenerated" : true,
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
"stringUnit" : {
|
||||
"state" : "new",
|
||||
"value" : " Zeichenzahl: %1$lld\n Unicode: %2$lld\n UTF-8 Bytes: %3$lld"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"drücken" : {
|
||||
"comment" : "A tab label for a tab that prints something.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Enter Emoji" : {
|
||||
"comment" : "A label for an text field where the user can enter an emoji.",
|
||||
"isCommentAutoGenerated" : true
|
||||
},
|
||||
"Hello, World!" : {
|
||||
"comment" : "A simple text view with padding applied to it.",
|
||||
"isCommentAutoGenerated" : true
|
||||
|
|
|
|||
|
|
@ -58,4 +58,9 @@ struct Bike: Vehicle, CustomStringConvertible {
|
|||
func emptyBasket() {
|
||||
print("emptied", Date())
|
||||
}
|
||||
static let all = [
|
||||
Bike(name: "Specialized",price: 100000.00, color: .purple ),
|
||||
Bike(name: "Giant",price: 120000.00, color: .red ),
|
||||
Bike(name: "Cannondale",price: 110000.00, color: .green )
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,8 @@ let train = Train { Bike.trek }
|
|||
#Playground {
|
||||
// bike.price
|
||||
// train.makeSomeNoise("Choo Choo!")
|
||||
train.content.name
|
||||
for bike in Bike.all {
|
||||
bike
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A842E92EC7A00271E8D /* App.swift */; };
|
||||
0CC14A892E92EEA900271E8D /* Playground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC14A882E92EEA900271E8D /* Playground.swift */; };
|
||||
FB2F07E92EA7CB25002BD499 /* ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FB2F07E82EA7CB25002BD499 /* ListView.swift */; };
|
||||
FBA00D6D2EA78411006F8B9A /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */; };
|
||||
FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D6E2EA78850006F8B9A /* Color.swift */; };
|
||||
FBA00D712EA7A839006F8B9A /* PaddingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D702EA7A830006F8B9A /* PaddingView.swift */; };
|
||||
FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D722EA7A96C006F8B9A /* ContentView.swift */; };
|
||||
FBA00D752EA7ACE1006F8B9A /* SwapperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D742EA7ACDD006F8B9A /* SwapperView.swift */; };
|
||||
FBA00D772EA7C235006F8B9A /* CountView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA00D762EA7C235006F8B9A /* CountView.swift */; };
|
||||
FBA6FA5E2EA63EA300C373EC /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA5D2EA63EA300C373EC /* Models.swift */; };
|
||||
FBA6FA602EA66C2E00C373EC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */; };
|
||||
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FBA6FA612EA76AAD00C373EC /* BikeView.swift */; };
|
||||
|
|
@ -25,11 +27,13 @@
|
|||
0CC14A762E92EC4700271E8D /* TheSwiftWeek.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TheSwiftWeek.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
0CC14A842E92EC7A00271E8D /* App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = App.swift; sourceTree = "<group>"; };
|
||||
0CC14A882E92EEA900271E8D /* Playground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Playground.swift; sourceTree = "<group>"; };
|
||||
FB2F07E82EA7CB25002BD499 /* ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListView.swift; sourceTree = "<group>"; };
|
||||
FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
|
||||
FBA00D6E2EA78850006F8B9A /* Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
|
||||
FBA00D702EA7A830006F8B9A /* PaddingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaddingView.swift; sourceTree = "<group>"; };
|
||||
FBA00D722EA7A96C006F8B9A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
FBA00D742EA7ACDD006F8B9A /* SwapperView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwapperView.swift; sourceTree = "<group>"; };
|
||||
FBA00D762EA7C235006F8B9A /* CountView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountView.swift; sourceTree = "<group>"; };
|
||||
FBA6FA5D2EA63EA300C373EC /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = "<group>"; };
|
||||
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
FBA6FA612EA76AAD00C373EC /* BikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BikeView.swift; sourceTree = "<group>"; };
|
||||
|
|
@ -57,10 +61,12 @@
|
|||
FBA6FA632EA7715000C373EC /* Extentions.swift */,
|
||||
0CC14A842E92EC7A00271E8D /* App.swift */,
|
||||
FBA00D722EA7A96C006F8B9A /* ContentView.swift */,
|
||||
FBA00D762EA7C235006F8B9A /* CountView.swift */,
|
||||
FBA6FA5F2EA66C2E00C373EC /* Assets.xcassets */,
|
||||
0CC14A882E92EEA900271E8D /* Playground.swift */,
|
||||
FBA6FA612EA76AAD00C373EC /* BikeView.swift */,
|
||||
FBA6FA652EA7725A00C373EC /* TrainView.swift */,
|
||||
FB2F07E82EA7CB25002BD499 /* ListView.swift */,
|
||||
FBA6FA5D2EA63EA300C373EC /* Models.swift */,
|
||||
FBA00D6C2EA78411006F8B9A /* Localizable.xcstrings */,
|
||||
0CC14A772E92EC4700271E8D /* Products */,
|
||||
|
|
@ -158,8 +164,10 @@
|
|||
0CC14A872E92EC7B00271E8D /* App.swift in Sources */,
|
||||
FBA00D732EA7A96C006F8B9A /* ContentView.swift in Sources */,
|
||||
FBA00D6F2EA78853006F8B9A /* Color.swift in Sources */,
|
||||
FB2F07E92EA7CB25002BD499 /* ListView.swift in Sources */,
|
||||
FBA00D712EA7A839006F8B9A /* PaddingView.swift in Sources */,
|
||||
FBA6FA622EA76AAD00C373EC /* BikeView.swift in Sources */,
|
||||
FBA00D772EA7C235006F8B9A /* CountView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue