article

Friday, May 7, 2021

SwiftUI How to adjust the position of a view using its offset

SwiftUI How to adjust the position of a view using its offset
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
//
//  ContentView.swift
//  Testapp
//
//  Created by Cairocoders
//
 
import SwiftUI
 
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Home")
                .background(Color.red)
            Text("Options")
                .offset(y: 15)
                .padding(.bottom, 15)
            Text("Help")
                .offset(y: 15)
                .padding(.bottom, 25)
             
            ZStack (alignment: .bottomTrailing) {
                Image("luppypic")
                    .resizable()
                    .frame(width: 250, height: 250, alignment: .center)
                Text("Luppy picture")
                    .padding(4)
                    .background(Color.black)
                    .foregroundColor(.white)
                    .offset(x: -5, y: -5)
            }
        }
    }
}
 
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
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
//
//  ContentView.swift
//  Testapp
//
//  Created by Cairocoders
//
 
import SwiftUI
 
struct ContentView: View {
    var body: some View {
        VStack {
            Text("Home")
                .background(Color.red)
                .offset(y: 15)
            Text("Options")
                .offset(y: 15)
                .padding(.bottom, 15)
            Text("Help")
                .background(Color.red)
             
             
            ZStack(alignment: .bottomTrailing){
                Image("luppy")
                Text("Luppy Photo")
                    .padding(4)
                    .background(Color.black)
                    .foregroundColor(.white)
                    .offset(x: -5, y: -5)
            }
        }
    }
}
 
struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Related Post