How to put space between the content and the top of the screen?

Hi guys, I want to put some space between the content and the top of the screen… I don’t know where exactly I have to write this command in my code, please help me.

Thank you

Answered by ForumsContributor in
Accepted Answer

Please explain the context:

  • SwiftUI or UIKit ?

If SwiftUI, use Spacer(), like in following example:

struct ChecklistRow: View {
    let name: String

    var body: some View {
        HStack {
            Spacer()
            Image(systemName: "checkmark")
            Text(name)
        }
        .border(Color.blue)
    }
}

if UIKit, use constraints (In interface builder) to position the view relative to safe area. Or create those constraints in viewDidLoad.

But in any case, formulate your question more precisely.

How to put space between the content and the top of the screen?
 
 
Q