Skip to content

Commit

Permalink
添加视觉相关内容
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed May 24, 2024
1 parent 9ae6c7d commit bc12bd2
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 27 deletions.
20 changes: 20 additions & 0 deletions SwiftPamphletApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@
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 */; };
087ECE3F2BFF8A690011F679 /* Blend Modes(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE3E2BFF8A690011F679 /* Blend Modes(ap).md */; };
087ECE412C00532F0011F679 /* SwiftUI-渐变(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE402C00532F0011F679 /* SwiftUI-渐变(ap).md */; };
087ECE432C0066740011F679 /* SwiftUI-模糊(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE422C0066740011F679 /* SwiftUI-模糊(ap).md */; };
087ECE452C006A170011F679 /* SwiftUI-背景材质(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE442C006A170011F679 /* SwiftUI-背景材质(ap).md */; };
087ECE472C00756C0011F679 /* AppIcon(ap).md in Resources */ = {isa = PBXBuildFile; fileRef = 087ECE462C00756C0011F679 /* AppIcon(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 @@ -555,6 +560,11 @@
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>"; };
087ECE3E2BFF8A690011F679 /* Blend Modes(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Blend Modes(ap).md"; sourceTree = "<group>"; };
087ECE402C00532F0011F679 /* SwiftUI-渐变(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI-渐变(ap).md"; sourceTree = "<group>"; };
087ECE422C0066740011F679 /* SwiftUI-模糊(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI-模糊(ap).md"; sourceTree = "<group>"; };
087ECE442C006A170011F679 /* SwiftUI-背景材质(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "SwiftUI-背景材质(ap).md"; sourceTree = "<group>"; };
087ECE462C00756C0011F679 /* AppIcon(ap).md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "AppIcon(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 @@ -658,6 +668,7 @@
isa = PBXGroup;
children = (
08026C322869991200792EF1 /* Swift-DocC(ap).md */,
087ECE462C00756C0011F679 /* AppIcon(ap).md */,
);
path = "系统能力";
sourceTree = "<group>";
Expand Down Expand Up @@ -1064,6 +1075,10 @@
children = (
08522BE327CF5C55005FF059 /* SwiftUI颜色(ap).md */,
087ECE3C2BFF491B0011F679 /* SwiftUI-Shadow(ap).md */,
087ECE3E2BFF8A690011F679 /* Blend Modes(ap).md */,
087ECE402C00532F0011F679 /* SwiftUI-渐变(ap).md */,
087ECE422C0066740011F679 /* SwiftUI-模糊(ap).md */,
087ECE442C006A170011F679 /* SwiftUI-背景材质(ap).md */,
08522BE827CF6E3A005FF059 /* SwiftUI Effect(ap).md */,
085BB77327D22FCA00E8F69A /* SwiftUI动画(ap).md */,
085BB77527D22FE300E8F69A /* SwiftUI Canvas(ap).md */,
Expand Down Expand Up @@ -1700,6 +1715,7 @@
0858C5C92BECCD17004F4C04 /* SwiftData-资料(ap).md in Resources */,
08D8EFED2BEF3F2100AA0020 /* 小组件-配置选项(ap).md in Resources */,
0844900F279ECC0C00B61353 /* Combine网络请求(ap).md in Resources */,
087ECE452C006A170011F679 /* SwiftUI-背景材质(ap).md in Resources */,
086BEF052BF6C38300025307 /* 文字Picker(ap).md in Resources */,
0850AC192BF35A26009FDBBF /* Grid(ap).md in Resources */,
08448F9A279EBA2900B61353 /* 可选(ap).md in Resources */,
Expand All @@ -1712,6 +1728,7 @@
0869233C2BF1BF35006779A3 /* ScrollView-参考资料(ap).md in Resources */,
08448FAF279EC31200B61353 /* 不透明类型(ap).md in Resources */,
08449029279ECEB100B61353 /* SwiftUI是什么(ap).md in Resources */,
087ECE432C0066740011F679 /* SwiftUI-模糊(ap).md in Resources */,
086BEEFE2BF644D400025307 /* GeometryReader(ap).md in Resources */,
087ECE0E2BFDE0630011F679 /* 自定义修饰符(ap).md in Resources */,
08448F79279EB68D00B61353 /* 随机(ap).md in Resources */,
Expand Down Expand Up @@ -1802,6 +1819,7 @@
087ECE252BFF25940011F679 /* 视图协议-核心协议(ap).md in Resources */,
08448F71279EB58C00B61353 /* Data(ap).md in Resources */,
08448FFE279ECAA100B61353 /* removeDuplicates(ap).md in Resources */,
087ECE472C00756C0011F679 /* AppIcon(ap).md in Resources */,
08D4EBE62BF4B8050031EDC5 /* 布局-对齐(ap).md in Resources */,
08D8EFEB2BEF106B00AA0020 /* 小组件-AppIntentConfiguration(ap).md in Resources */,
0850445827B1228E0096D556 /* Result(ap).md in Resources */,
Expand Down Expand Up @@ -1889,6 +1907,7 @@
08448F9E279EBAA800B61353 /* 函数(ap).md in Resources */,
08448FEC279EC8BE00B61353 /* 注释(ap).md in Resources */,
08D8F0002BEFA72300AA0020 /* 获取小组件形状(ap).md in Resources */,
087ECE3F2BFF8A690011F679 /* Blend Modes(ap).md in Resources */,
08026C4E2869B3B500792EF1 /* ShareLink(ap).md in Resources */,
08026C432869B22E00792EF1 /* Regex(ap).md in Resources */,
08D4EBDD2BF461F60031EDC5 /* 自定义导航栏(ap).md in Resources */,
Expand All @@ -1900,6 +1919,7 @@
08D8EFFA2BEF9C9800AA0020 /* 小组件-远程定时获取数据(ap).md in Resources */,
0850AC102BF30058009FDBBF /* List-完全可点击的行(ap).md in Resources */,
087ECE1A2BFEA8210011F679 /* 修饰符-蒙版(ap).md in Resources */,
087ECE412C00532F0011F679 /* SwiftUI-渐变(ap).md in Resources */,
0858C5C72BEBD230004F4C04 /* ContentUnavailableView(ap).md in Resources */,
086BEF0F2BF6C43800025307 /* WheelPicker(ap).md in Resources */,
087ECE082BFCC3D90011F679 /* HUD(ap).md in Resources */,
Expand Down
10 changes: 6 additions & 4 deletions SwiftPamphletApp/App/IntroView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ struct LightingView<Content: View>: View {
struct IntroView: View {
var body: some View {
VStack(spacing: 15) {
Image("logo")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 120, height: 120)
if let appIcon = NSImage(named: "AppIcon") {
Image(nsImage: appIcon)
.resizable()
.scaledToFit()
.frame(width: 120, height: 120)
}
Text("戴铭的开发小册子").bold()
LightingView {
Text("Swift Pamphlet App").gradientTitle(color: .mint)
Expand Down
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions SwiftPamphletApp/Assets.xcassets/logo.imageset/Contents.json

This file was deleted.

7 changes: 6 additions & 1 deletion SwiftPamphletApp/Guide/View/GuideListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ final class GuideListModel {
L(t: "视觉",sub: [
L(t: "SwiftUI颜色"),
L(t: "SwiftUI-Shadow"),
L(t: "Blend Modes"),
L(t: "SwiftUI-渐变"),
L(t: "SwiftUI-模糊"),
L(t: "SwiftUI-背景材质"),
L(t: "SwiftUI Effect"),
L(t: "SwiftUI动画"),
L(t: "SwiftUI Canvas"),
Expand Down Expand Up @@ -428,7 +432,8 @@ final class GuideListModel {
L(t: "小组件-参考资料", icon: "books.vertical"),
]),
L(t: "系统能力",icon: "apple.terminal",sub: [
L(t: "Swift-DocC", icon: "doc.append")
L(t: "Swift-DocC", icon: "doc.append"),
L(t: "AppIcon", icon: "app")
]),
L(t: "工程模式",icon: "building.columns", sub: [
L(t: "单例"),
Expand Down
83 changes: 83 additions & 0 deletions SwiftPamphletApp/Resource/Guide/SwiftUI/视觉/Blend Modes(ap).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

Blend Modes

### 介绍

`blendMode(_:)` 是 SwiftUI 中的一个视图修饰符,用于混合视图。以下是两种使用 `blendMode(_:)` 的方式,以及相应的示例:

1. 通过 `ZStack` 使用 `blendMode(_:)`

```swift
struct ContentView: View {
var body: some View {
ZStack {
Image("evermore")
Image("fearless")
.blendMode(.multiply)
}
}
}
```

在这个例子中,我们创建了一个 `ZStack`,它包含两个图像。我们将 `blendMode(.multiply)` 应用于第二个图像,这样它就会与第一个图像混合。

2. 通过 `.overlay` 使用 `blendMode(_:)`

```swift
struct ContentView: View {
var body: some View {
Image("evermore")
.overlay {
Image("fearless")
.blendMode(.color)
.blendMode(.multiply)
}
}
}
```

在这个例子中,我们创建了一个图像,并添加了一个覆盖层。这个覆盖层是另一个图像,我们将 `blendMode(.multiply)` 应用于这个图像,这样它就会与底层的图像混合。

`.multiply` 是一种混合模式,你可以根据需要选择其他的混合模式。

blendMode 混合模式可以分为以下几种类型:

## 变亮

提升亮部亮度

- `colorDodge`
- `lighten`
- `screen`
- `plusLighter`

## 变暗

使暗部更暗

- `colorBurn`
- `darken`
- `multiply`
- `plusDarker`

## 对比

让亮部更亮,暗部更暗,对比度增加,更艳丽。

- `overlay`
- `softLight`
- `hardLight`

## 融合

这些模式会根据源图像和目标图像的色调、饱和度、颜色或亮度进行混合。

- `hue`
- `saturation`
- `color`
- `luminosity`
- `sourceAtop`
- `destinationOver`
- `destinationOut`
- `difference`
- `exclusion`
124 changes: 124 additions & 0 deletions SwiftPamphletApp/Resource/Guide/SwiftUI/视觉/SF Symbol(ap).md
Original file line number Diff line number Diff line change
@@ -1,2 +1,126 @@


## 演进

在 iOS 13 中,苹果引入了 SF Symbols,这是一套专门为 Apple 设备设计的符号图标,可以在应用程序中使用。这些符号图标是矢量图形,可以在不同的大小和颜色下保持清晰度。

WWDC 21 符号数量达到 3000 个,包括 500 个全新的符号,以及 1000 个符号的变体。推出了 SF Symbols 3,支持更多的变体和颜色。可以自定义符号。

WWDC 22 推出了 SF Symbols 4,数量达到 4000 个,支持更多的变体和颜色。有自动渲染模式,还有可变颜色。

WWDC 23 推出了 SF Symbols 5,数量达到 5000 个。符号有7种动画,可以定制动画。可以用 Symbol Components 来创建自定义符号。

## 变量值

SF Symbol 支持变量值,可以通过设置 variableValue 来填充不同部分,比如 wifi 图标,不同值会亮不同部分,`Image(systemName: "wifi", variableValue: 0.5)`

下面是一个使用变量值的示例代码:

```swift
struct ContentView: View {
@State private var variableValue: Double = 0.5

var body: some View {
VStack {
Slider(value: $variableValue, in: 0...1, step: 0.01)
Image(systemName: "speaker.wave.3.fill", variableValue: variableValue)
.symbolRenderingMode(.palette)
.symbolVariant(.fill)
.foregroundColor(.blue)
.imageScale(.large)
}
.padding()
}
}
```

## 大小

`.imageScale` 可以改变 SF Symbol 的大小,可以设置为 `.small``.medium``.large`

```swift
struct ContentView: View {
var body: some View {
Image(systemName: "wifi")
.imageScale(.large)
}
}
```

还可以通过 `.font(.system(size:``.fontWeight(.semibold)` 来设置大小和粗细。

## 文本插值

文本插值支持 SF Symbol,可以在文本中插入 SF Symbol。

```swift
Text("这是一辆双层 \(Image(systemName: "bus.doubledecker"))")
```

## symbolRenderingMode 渲染模式

symbolRenderingMode 可以设置 SF Symbol 的渲染模式,可以设置为 `.multicolor``.palette``.monochrome``.hierarchical`

- `.multicolor`:多色模式。这种模式下,SF Symbols 将使用预定义的多种颜色来显示。这是默认的渲染模式。
- `.palette`:调色板模式。这种模式下,SF Symbols 将使用你指定的颜色来显示。你可以为每个部分指定不同的颜色。
- `.monochrome`:单色模式。这种模式下,SF Symbols 将使用单一颜色来显示。这个颜色是你在代码中指定的颜色。
- `.hierarchical`:层次模式。这种模式下,SF Symbols 将使用一种颜色,但是不同的部分会有不同的透明度。这可以创建出一种层次感。

以下是一个使用 `.multicolor` 渲染模式的示例代码:

```swift
struct ContentView: View {
var body: some View {
Image(systemName: "figure.walk.motion.trianglebadge.exclamationmark")
.symbolRenderingMode(.multicolor)
}
}
```

## symbolVariant 变体

symbolVariant 可以设置 SF Symbol 的变体,可以设置为 `.none``.circle``.square``.rectangle``.fill``.slash`

当然,以下是 SF Symbols 的各种变体的详细介绍:

1. `none`:没有任何特殊变体的 SF Symbol。

2. `circle`:这个变体的 SF Symbol 是在一个圆形背景中的。例如,`circle` 变体的 "person" symbol 就是一个人像在一个圆形背景中。

3. `square`:这个变体的 SF Symbol 是在一个正方形背景中的。例如,`square` 变体的 "person" symbol 就是一个人像在一个正方形背景中。

4. `rectangle`:这个变体的 SF Symbol 是在一个矩形背景中的。例如,`rectangle` 变体的 "person" symbol 就是一个人像在一个矩形背景中。

5. `fill`:这个变体的 SF Symbol 是填充的,也就是说,它的内部是有颜色的,而不是空心的。例如,`fill` 变体的 "heart" symbol 就是一个填充的心形。

6. `slash`:这个变体的 SF Symbol 是有一条斜线穿过的。例如,`slash` 变体的 "bell" symbol 就是一个有斜线穿过的铃铛,表示静音。


```swift
struct ContentView: View {
var body: some View {
VStack(alignment: .leading) {
Label("Default", systemImage: "person")
Label("Circle", systemImage: "circle")
.symbolVariant(.circle)
Label("Circle Fill", systemImage: "circle.fill")
.symbolVariant(.circle.fill)
Label("Square", systemImage: "square")
.symbolVariant(.square)
Label("Square Fill", systemImage: "square.fill")
.symbolVariant(.square.fill)
Label("Rectangle", systemImage: "rectangle")
.symbolVariant(.rectangle)
Label("Rectangle Fill", systemImage: "rectangle.fill")
.symbolVariant(.rectangle.fill)
Label("Fill", systemImage: "heart")
.symbolVariant(.fill)
Label("Slash", systemImage: "bell")
.symbolVariant(.slash)
Label("Slash Fill", systemImage: "bell.fill")
.symbolVariant(.slash.fill)
}
}
}

```
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@


## shadow

卡片阴影效果

```swift
.shadow(color: Color(.sRGB, red: 0, green: 0, blue: 0, opacity: 0.25), radius: 10, x: 0, y: 0)
```

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

```swift
Expand All @@ -24,6 +33,7 @@ struct ContentView: View {

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


## 多重阴影,发光效果

```swift
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

三方库

- [daprice/Variablur: Variable blur effects for SwiftUI, powered by Metal](https://github.com/daprice/Variablur)
- [joogps/Glur: Progressive blurs in SwiftUI.](https://github.com/joogps/Glur)
Loading

0 comments on commit bc12bd2

Please sign in to comment.