feat(contentview): 创建 cardview
可以加减卡片数量 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
eafc410472
commit
673adb8752
94
.gitignore
vendored
Normal file
94
.gitignore
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## User settings
|
||||
xcuserdata/
|
||||
|
||||
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
|
||||
*.xcscmblueprint
|
||||
*.xccheckout
|
||||
|
||||
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
|
||||
build/
|
||||
DerivedData/
|
||||
*.moved-aside
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
|
||||
## Obj-C/Swift specific
|
||||
*.hmap
|
||||
|
||||
## App packaging
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
||||
# Swift Package Manager
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
|
||||
# Packages/
|
||||
# Package.pins
|
||||
# Package.resolved
|
||||
# *.xcodeproj
|
||||
#
|
||||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
|
||||
# hence it is not needed unless you have added a package configuration file to your project
|
||||
# .swiftpm
|
||||
|
||||
.build/
|
||||
|
||||
# CocoaPods
|
||||
#
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
#
|
||||
# Pods/
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from the Xcode workspace
|
||||
# *.xcworkspace
|
||||
|
||||
# Carthage
|
||||
#
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build/
|
||||
|
||||
# Accio dependency management
|
||||
Dependencies/
|
||||
.accio/
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo.
|
||||
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/#source-control
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/test_output
|
||||
|
||||
# Code Injection
|
||||
#
|
||||
# After new code Injection tools there's a generated folder /iOSInjectionProject
|
||||
# https://github.com/johnno1962/injectionforxcode
|
||||
|
||||
iOSInjectionProject/
|
||||
|
||||
|
||||
*/xcuserdata/*
|
||||
|
||||
@ -70,6 +70,11 @@
|
||||
"scale" : "2x",
|
||||
"size" : "40x40"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"scale" : "1x",
|
||||
"size" : "76x76"
|
||||
},
|
||||
{
|
||||
"idiom" : "ipad",
|
||||
"scale" : "2x",
|
||||
|
||||
@ -8,14 +8,92 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
var emojis = ["🚌", "🚙", "🚗", "🚕", "🏎", "🚎", "🚓"]
|
||||
@State var emojiCount = 2
|
||||
var body: some View {
|
||||
Text("Hello, world!")
|
||||
.padding()
|
||||
VStack {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 65))]) {
|
||||
ForEach(emojis[0..<emojiCount], id: \.self) {
|
||||
emoji in CardView(content: emoji).aspectRatio(2/3, contentMode: .fit)
|
||||
}
|
||||
}
|
||||
}
|
||||
.foregroundColor(/*@START_MENU_TOKEN@*/.red/*@END_MENU_TOKEN@*/)
|
||||
Spacer()
|
||||
HStack{
|
||||
remove
|
||||
Spacer()
|
||||
add
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.font(.largeTitle)
|
||||
}
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
var remove: some View {
|
||||
Button(action: {
|
||||
if emojiCount > 1{
|
||||
emojiCount -= 1
|
||||
}
|
||||
}, label: {
|
||||
Image(systemName: "minus.circle")
|
||||
})
|
||||
}
|
||||
var add: some View {
|
||||
Button(action: {
|
||||
if emojiCount < emojis.count {
|
||||
emojiCount += 1
|
||||
}
|
||||
}, label: {
|
||||
Image(systemName: "plus.circle")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct CardView: View {
|
||||
@State var isFaceUp: Bool = true
|
||||
var content: String
|
||||
var body: some View {
|
||||
ZStack {
|
||||
let shape = RoundedRectangle(cornerRadius: 20.0)
|
||||
if isFaceUp {
|
||||
shape
|
||||
.fill()
|
||||
.foregroundColor(.white)
|
||||
shape
|
||||
.strokeBorder(lineWidth: 3)
|
||||
Text(content)
|
||||
.font(.largeTitle)
|
||||
}
|
||||
else {
|
||||
shape
|
||||
.fill()
|
||||
}
|
||||
}
|
||||
.onTapGesture {
|
||||
isFaceUp = !isFaceUp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
.preferredColorScheme(.dark)
|
||||
ContentView()
|
||||
.preferredColorScheme(.light)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user