feat(view, contstants): 修改 card 中字体大小为自适应;增加 constants
修改 card 中字体大小为自适应;增加 constants Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
449fa1b8e9
commit
08dc4700a3
@ -13,6 +13,7 @@
|
|||||||
240EDC462998A3BA00A46AC9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 240EDC452998A3BA00A46AC9 /* Preview Assets.xcassets */; };
|
240EDC462998A3BA00A46AC9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 240EDC452998A3BA00A46AC9 /* Preview Assets.xcassets */; };
|
||||||
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 245099F22998EAD6000CE9DA /* MemoryGame.swift */; };
|
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 245099F22998EAD6000CE9DA /* MemoryGame.swift */; };
|
||||||
245099F52998EC71000CE9DA /* EmojiMemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */; };
|
245099F52998EC71000CE9DA /* EmojiMemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */; };
|
||||||
|
24E748FC29993782009B5FE8 /* Constans.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24E748FB29993781009B5FE8 /* Constans.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@ -23,6 +24,7 @@
|
|||||||
240EDC452998A3BA00A46AC9 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
240EDC452998A3BA00A46AC9 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||||
245099F22998EAD6000CE9DA /* MemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryGame.swift; sourceTree = "<group>"; };
|
245099F22998EAD6000CE9DA /* MemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryGame.swift; sourceTree = "<group>"; };
|
||||||
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGame.swift; sourceTree = "<group>"; };
|
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGame.swift; sourceTree = "<group>"; };
|
||||||
|
24E748FB29993781009B5FE8 /* Constans.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constans.swift; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@ -57,6 +59,7 @@
|
|||||||
children = (
|
children = (
|
||||||
240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */,
|
240EDC3E2998A3B900A46AC9 /* MemorizeApp.swift */,
|
||||||
240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */,
|
240EDC402998A3B900A46AC9 /* EmojiMemoryGameView.swift */,
|
||||||
|
24E748FB29993781009B5FE8 /* Constans.swift */,
|
||||||
245099F22998EAD6000CE9DA /* MemoryGame.swift */,
|
245099F22998EAD6000CE9DA /* MemoryGame.swift */,
|
||||||
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */,
|
245099F42998EC71000CE9DA /* EmojiMemoryGame.swift */,
|
||||||
240EDC422998A3BA00A46AC9 /* Assets.xcassets */,
|
240EDC422998A3BA00A46AC9 /* Assets.xcassets */,
|
||||||
@ -145,6 +148,7 @@
|
|||||||
files = (
|
files = (
|
||||||
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */,
|
245099F32998EAD6000CE9DA /* MemoryGame.swift in Sources */,
|
||||||
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */,
|
240EDC412998A3B900A46AC9 /* EmojiMemoryGameView.swift in Sources */,
|
||||||
|
24E748FC29993782009B5FE8 /* Constans.swift in Sources */,
|
||||||
240EDC3F2998A3B900A46AC9 /* MemorizeApp.swift in Sources */,
|
240EDC3F2998A3B900A46AC9 /* MemorizeApp.swift in Sources */,
|
||||||
245099F52998EC71000CE9DA /* EmojiMemoryGame.swift in Sources */,
|
245099F52998EC71000CE9DA /* EmojiMemoryGame.swift in Sources */,
|
||||||
);
|
);
|
||||||
|
|||||||
20
Memorize/Constans.swift
Normal file
20
Memorize/Constans.swift
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// Constans.swift
|
||||||
|
// Memorize
|
||||||
|
//
|
||||||
|
// Created by ching on 2023/2/12.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct const {
|
||||||
|
enum DrawingConstants {
|
||||||
|
static let cornerRadius: CGFloat = 20
|
||||||
|
static let lineWidth: CGFloat = 3
|
||||||
|
static let fontScale: CGFloat = 0.8
|
||||||
|
static let gridWidth: CGFloat = 80
|
||||||
|
static let gridAspectRatio: CGFloat = 2 / 3
|
||||||
|
static let matchedCardOpacity: Double = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,9 +11,9 @@ struct EmojiMemoryGameView: View {
|
|||||||
@ObservedObject var game: EmojiMemoryGame
|
@ObservedObject var game: EmojiMemoryGame
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 65))]) {
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: const.DrawingConstants.gridWidth))]) {
|
||||||
ForEach(game.cards) {
|
ForEach(game.cards) {
|
||||||
card in CardView(card: card).aspectRatio(2 / 3, contentMode: .fit)
|
card in CardView(card: card).aspectRatio(const.DrawingConstants.gridAspectRatio, contentMode: .fit)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
game.choose(card)
|
game.choose(card)
|
||||||
}
|
}
|
||||||
@ -27,20 +27,28 @@ struct EmojiMemoryGameView: View {
|
|||||||
|
|
||||||
struct CardView: View {
|
struct CardView: View {
|
||||||
let card: EmojiMemoryGame.Card
|
let card: EmojiMemoryGame.Card
|
||||||
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
GeometryReader { geometry in
|
||||||
let shape = RoundedRectangle(cornerRadius: 20.0)
|
ZStack {
|
||||||
if card.isFaceUp && !card.isMatched {
|
let shape = RoundedRectangle(cornerRadius: const.DrawingConstants.cornerRadius)
|
||||||
shape.fill().foregroundColor(.white)
|
if card.isFaceUp && !card.isMatched {
|
||||||
shape.strokeBorder(lineWidth: 3)
|
shape.fill().foregroundColor(.white)
|
||||||
Text(card.content).font(.largeTitle)
|
shape.strokeBorder(lineWidth: const.DrawingConstants.lineWidth)
|
||||||
} else if card.isMatched {
|
Text(card.content).font(font(in: geometry.size))
|
||||||
shape.opacity(0)
|
} else if card.isMatched {
|
||||||
} else {
|
shape.opacity(const.DrawingConstants.matchedCardOpacity)
|
||||||
shape.fill()
|
} else {
|
||||||
|
shape.fill()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func font(in size: CGSize) -> Font {
|
||||||
|
Font.system(size: min(size.width, size.height) * const.DrawingConstants.fontScale)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContentView_Previews: PreviewProvider {
|
struct ContentView_Previews: PreviewProvider {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user