-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathSafeAreaPadding.swift
77 lines (62 loc) · 1.86 KB
/
SafeAreaPadding.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// ContentView.swift
// SafeAreaPadding
//
// Created by Ganesh Raju Galla on 22/01/24.
//
import SwiftUI
struct ContentView: View {
// MARK: - Properties
@State private var selectedTab:Tab = .padding
// MARK: - Body
var body: some View {
NavigationStack{
VStack {
// Picker
Picker("Select Tab", selection: $selectedTab) {
ForEach(Tab.allCases,id: \.id){ itme in
Text(itme.rawValue.localizedUppercase)
.tag(itme)
}
}
.pickerStyle(.segmented)
Spacer()
// scrollView
ScrollView(.horizontal,showsIndicators:false){
HStack(spacing: 10){
ForEach(0..<10){ _ in
RoundedRectangle(cornerRadius: 10)
.foregroundStyle(Color.blue)
.frame(height: 250)
.containerRelativeFrame(.horizontal)
}
}
}
Spacer()
}
.if(selectedTab == .padding) { view in
view.padding(.horizontal,10)
}
.if(selectedTab == .safeAreaPadding) { view in
view.safeAreaPadding(.horizontal, 10)
}
}
}
}
extension View {
@ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {
self
}
}
}
#Preview {
ContentView()
}
enum Tab:String, CaseIterable,Identifiable{
case padding
case safeAreaPadding
var id:Tab{self}
}