Skip to content

Commit

Permalink
新增 shadow 效果内容
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 23, 2024
1 parent 82bfec2 commit 9ae6c7d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 戴铭的开发小册子 6.0
[![Available on the App Store](https://ming1016.github.io/qdimg/badge-download-on-the-mac-app-store.svg)](https://apps.apple.com/cn/app/id1609702529)

Swift开发的手册,是个 macOS 程序,已上线macOS应用商店,[点击安装](https://apps.apple.com/cn/app/%E6%88%B4%E9%93%AD%E7%9A%84%E5%BC%80%E5%8F%91%E5%B0%8F%E5%86%8C%E5%AD%90/id1609702529?mt=12),或直接在商店搜索“戴铭”关键字,方便更新程序。小册子文字版 [戴铭的 Swift 小册子](https://ming1016.github.io/2021/11/23/daiming-swift-pamphlet/)
Swift开发的手册,是个 macOS 程序,已上线macOS应用商店,[点击购买安装(98元)](https://apps.apple.com/cn/app/%E6%88%B4%E9%93%AD%E7%9A%84%E5%BC%80%E5%8F%91%E5%B0%8F%E5%86%8C%E5%AD%90/id1609702529?mt=12),或直接在商店搜索“戴铭”关键字。安装应用方便更新程序。小册子5.0 的文字版 [戴铭的 Swift 小册子](https://ming1016.github.io/2021/11/23/daiming-swift-pamphlet/),6.0 新增的文字内容也可以在我博客上看。

使用 SwiftData、Observable、NavigationSplitView 进行了重构,现在可自己添加管理资料,和知识点做关联。
本手册使用 SwiftData、Observable、NavigationSplitView 进行了重构,现在可自己添加管理资料,和知识点做关联。

内容主要包含

Expand Down
4 changes: 4 additions & 0 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
087ECE372BFF26790011F679 /* Toolbar协议(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE362BFF26790011F679 /* Toolbar协议(ap).md */; };
087ECE392BFF26910011F679 /* Documents协议(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE382BFF26910011F679 /* Documents协议(ap).md */; };
087ECE3B2BFF26B00011F679 /* 特定情况视图协议(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE3A2BFF26B00011F679 /* 特定情况视图协议(ap).md */; };
087ECE3D2BFF491B0011F679 /* SwiftUI-Shadow(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE3C2BFF491B0011F679 /* SwiftUI-Shadow(ap).md */; };
0887A59A2BA28F6D00131359 /* CSGuideView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0887A5992BA28F6D00131359 /* CSGuideView.swift */; };
0896FB9227BA486900676B7F /* Button(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 0896FB9127BA486900676B7F /* Button(ap).md */; };
08A4FDC227B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 08A4FDC127B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md */; };
Expand Down Expand Up @@ -553,6 +554,7 @@
087ECE362BFF26790011F679 /* Toolbar协议(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Toolbar协议(ap).md"; sourceTree = "<group>"; };
087ECE382BFF26910011F679 /* Documents协议(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Documents协议(ap).md"; sourceTree = "<group>"; };
087ECE3A2BFF26B00011F679 /* 特定情况视图协议(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "特定情况视图协议(ap).md"; sourceTree = "<group>"; };
087ECE3C2BFF491B0011F679 /* SwiftUI-Shadow(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI-Shadow(ap).md"; sourceTree = "<group>"; };
0887A5992BA28F6D00131359 /* CSGuideView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSGuideView.swift; sourceTree = "<group>"; };
0896FB9127BA486900676B7F /* Button(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "Button(ap).md"; sourceTree = "<group>"; };
08A4FDC127B25A140068E5BC /* @dynamicMemberLookup动态成员查询(ap).md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = "@dynamicMemberLookup动态成员查询(ap).md"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1061,6 +1063,7 @@
isa = PBXGroup;
children = (
08522BE327CF5C55005FF059 /* SwiftUI颜色(ap).md */,
087ECE3C2BFF491B0011F679 /* SwiftUI-Shadow(ap).md */,
08522BE827CF6E3A005FF059 /* SwiftUI Effect(ap).md */,
085BB77327D22FCA00E8F69A /* SwiftUI动画(ap).md */,
085BB77527D22FE300E8F69A /* SwiftUI Canvas(ap).md */,
Expand Down Expand Up @@ -1892,6 +1895,7 @@
08BE636427C886D2002BC6A8 /* LazyVStack和LazyHStack(ap).md in Resources */,
08449030279ECF7D00B61353 /* 1.md in Resources */,
087ECE352BFF26620011F679 /* Responder chain协议(ap).md in Resources */,
087ECE3D2BFF491B0011F679 /* SwiftUI-Shadow(ap).md in Resources */,
08522BDA27CF5029005FF059 /* Slider(ap).md in Resources */,
08D8EFFA2BEF9C9800AA0020 /* 小组件-远程定时获取数据(ap).md in Resources */,
0850AC102BF30058009FDBBF /* List-完全可点击的行(ap).md in Resources */,
Expand Down
1 change: 1 addition & 0 deletions SwiftPamphletApp/Guide/View/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ final class GuideListModel {
]),
L(t: "视觉",sub: [
L(t: "SwiftUI颜色"),
L(t: "SwiftUI-Shadow"),
L(t: "SwiftUI Effect"),
L(t: "SwiftUI动画"),
L(t: "SwiftUI Canvas"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ struct ContentView: View {
}
```

## containerRelativeFrame 控制划动单元显示范围

containerRelativeFrame 可以控制划动单元显示范围,可以控制单个内容一页,也可以控制多个内容一页。

以下是 containerRelativeFrame 的使用示例:

```swift
struct ContentView: View {

var body: some View {
ScrollView(.horizontal) {
HStack(spacing: 10.0) {
ForEach(0...20, id: \.self) { _ in
Image("evermore")
.resizable()
.scaledToFit()
.containerRelativeFrame(.horizontal, count: 4, span: 3, spacing: 8)
}
}
}
.scrollTargetBehavior(.paging)
.safeAreaPadding(.horizontal, 20.0)
}
}
```

以上代码中,我们使用 containerRelativeFrame 修饰符,将每个 Image 视图的宽度设置为容器宽度的 3/4。我们还设置了每个 Image 视图之间的间距为 8 点。






Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

## `.shadow(.drop(radius:` 前景阴影

```swift
struct ContentView: View {
var body: some View {
Image(systemName: "film")
.frame(width: 200, height: 200)
.background(Color.mint)
.foregroundStyle(Color.white.shadow(.drop(radius: 1, y: 2.0)))
.font(.system(size: 80))
.overlay {
VStack {
Spacer()
Text("电影")
.font(.largeTitle)
.foregroundStyle(Color.white.shadow(.drop(radius: 1, y: 2.0)))
.padding()
}
}
}
}
```

以上代码中,我们使用了 `shadow(.drop(radius: y:))` 修饰符为图像和文本添加了阴影效果。这个修饰符接受两个参数:`radius``y``radius` 参数控制阴影的模糊半径,`y` 参数控制阴影的偏移量。

## 多重阴影,发光效果

```swift
struct ContentView: View {
var body: some View {
ZStack {
Rectangle()
.foregroundStyle(.black)
Image(systemName: "film")
.frame(width: 200, height: 200)
.background(Color.mint)
.foregroundStyle(Color.white.shadow(.drop(radius: 2, y: 4.0)))
.shadow(color: .white.opacity(0.3), radius: 100)
.shadow(color: .white.opacity(0.5), radius: 80)
.shadow(color: .white.opacity(0.6), radius: 30)
.shadow(color: .white.opacity(0.7), radius: 10)
.font(.system(size: 80))
.overlay {
VStack {
Spacer()
Text("电影")
.font(.largeTitle)
.foregroundStyle(Color.white.shadow(.drop(radius: 2, y: 4.0)))
.padding()
}
}
}
}
}
```

0 comments on commit 9ae6c7d

Please sign in to comment.