Skip to content

Commit 8950500

Browse files
committed
alignmentguide sample
1 parent 52dea7b commit 8950500

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

SwiftUIPlayground/Samples.swift

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public let samples: [String: AnyView] = [
4343
"Container Relative Frame": AnyView(ContainerRelativeFrameSample()),
4444
// https://developer.apple.com/documentation/swiftui/view/safeareainset(edge:alignment:spacing:content:)-6gwby
4545
"safeAreaInset": AnyView(SafeAreaInsetSample()),
46+
// https://developer.apple.com/documentation/swiftui/view/alignmentguide(_:computevalue:)-6y3u2
47+
"alignmentGuide": AnyView(AlignmentGuideSample()),
4648
]
4749
)),
4850
"Drawing and Graphics": AnyView(SamplesList(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// AlignmentGuideSample.swift
3+
// SwiftUIPlayground
4+
//
5+
// Created by Taha Tesser on 10/14/24.
6+
//
7+
8+
import SwiftUI
9+
10+
struct AlignmentGuideSample: View {
11+
12+
var body: some View {
13+
VStack(alignment: .leading) {
14+
RoundedRectangle(cornerRadius: 20)
15+
.fill(Color.red)
16+
.frame(width: 50, height: 200)
17+
// .alignmentGuide(.leading, computeValue: { dimension in
18+
// -100
19+
// })
20+
.alignmentGuide(.leading, computeValue: { dimension in
21+
dimension[.trailing]
22+
})
23+
Text("Testing the alignment")
24+
.border(.orange)
25+
.frame(width: 250, height: 50)
26+
// .alignmentGuide(.leading, computeValue: { dimension in
27+
// dimension[.trailing]
28+
// })
29+
RoundedRectangle(cornerRadius: 20)
30+
.fill(Color.blue)
31+
.frame(width: 100, height: 100)
32+
RoundedRectangle(cornerRadius: 20)
33+
.fill(Color.green)
34+
.frame(width: 50, height: 50)
35+
}
36+
37+
}
38+
39+
}
40+
41+
#Preview {
42+
AlignmentGuideSample()
43+
}

0 commit comments

Comments
 (0)