Home > AI > IOS > SwiftUI >

padding

Example 1: get default padding value

import Foundation
import SwiftUI

struct DefaultView: View {
    @Binding var padding: CGFloat
    @State var isHidden = false

    var body: some View {
        if !isHidden {
            Rectangle()
                .frame(width: 10, height: 10)
                .padding(.top)
                .foregroundColor(Color.red)
                .background(GeometryReader { geometry in
                    Rectangle()
                        .foregroundColor(Color.blue)
//                        .onAppear {
//                        self.padding = geometry.size.height
//                        self.isHidden = true
//                    }
                })
        }
    }
}


struct ExampleView: View {
    @State var padding = CGFloat()

    
    var body: some View {
        DefaultView(padding: $padding)
        Rectangle().frame(width: padding, height: padding)
    }
}

Leave a Reply