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
 
//
//  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()
    }
}
 
//
//  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