-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
SwiftPamphletApp/Resource/Guide/SwiftUI/视觉/SwiftUI-Shadow(ap).md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|