Skip to content

Commit e9ca4fd

Browse files
jlewrSSwiniarskiyangc95
authored
Add entry for SwiftUI Spacer (#2174)
* Add explanation and images for SwiftUI Spacer * Update SwiftUI Spacer description and examples * Fix spacing issues in Spacer.md * Fix image link formatting * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update content/swiftui/concepts/views/terms/spacer/spacer.md Co-authored-by: SSwiniarski <[email protected]> * Update spacer.md * Update spacer.md * Update spacer.md * Fix format --------- Co-authored-by: SSwiniarski <[email protected]> Co-authored-by: Christine Yang <[email protected]>
1 parent eff6ee3 commit e9ca4fd

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
Title: 'Spacer'
3+
Description: 'Creates space between views.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Developer Tools'
7+
- 'iOS'
8+
- 'Mobile Development'
9+
Tags:
10+
- 'Interface'
11+
- 'iOS'
12+
- 'Swift UI'
13+
- 'Swift UI Views'
14+
- 'Views'
15+
CatalogContent:
16+
- 'learn-swiftui'
17+
- 'paths/builds-ios-apps-with-swiftui'
18+
---
19+
20+
A **`Spacer`** view is an adaptive view that creates space between views. It expands in dimensions as much as the parent view will allow.
21+
22+
## Syntax
23+
24+
```pseudo
25+
Spacer()
26+
```
27+
28+
## Examples
29+
30+
In the example below, the `Spacer()` in the `HStack` fills the view to the left of the `Text`, effectively pushing the `Text` to the right.
31+
32+
```swift
33+
var body: some View {
34+
HStack {
35+
Spacer()
36+
Text("Example")
37+
}
38+
}
39+
```
40+
41+
This will display the following:
42+
43+
![SwiftUI Spacer Example 1](https://raw.githubusercontent.com/Codecademy/docs/main/media/swiftui-spacer-left.png)
44+
45+
In the next example below, each `Spacer()` fills the view on both the left and right of the `Text`. This effectively pushes the `Text` into the center, with each `Spacer` expanding as much as the parent view will allow on each side.
46+
47+
```swift
48+
var body: some View {
49+
HStack {
50+
Spacer()
51+
Text("Example")
52+
Spacer()
53+
}
54+
}
55+
```
56+
57+
This will display the following:
58+
59+
![SwiftUI Spacer Example 2](https://raw.githubusercontent.com/Codecademy/docs/main/media/swiftui-spacer-left-and-right.png)
17.5 KB
Loading

media/swiftui-spacer-left.png

18.4 KB
Loading

0 commit comments

Comments
 (0)