0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIで画像とテキストを表示する(チュートリアル)

Last updated at Posted at 2020-05-04

##画像とテキストを表示する
SwiftUIで写真を表示するテキストを表示するHStack,VStackの組み合わせです。
2020-05-04 10.53のイメージ.jpg

画像は画像だけを表示するswiftファイルとテキストだけを表示するswiftファイルを作成し、それらをインスタンス化
して表示させています。

import SwiftUI

struct Introduce: View {
    var body: some View {
        VStack {
            CircleImage()
            ContentView()
        }
    }
}

struct Introduce_Previews: PreviewProvider {
    static var previews: some View {
        Introduce()
    }
}

CircleImage

import SwiftUI

struct CircleImage: View {
    var body: some View {
        Image("8D23A0D7-AB6F-477F-BDED-00D4C8804B99_1_105_c")
        .resizable()
        .clipShape(Circle())
        .overlay(
            Circle().stroke(Color.gray, lineWidth: 4))
            .aspectRatio(contentMode: .fit)
        .shadow(radius: 10)
    }
}

struct CircleImage_Previews: PreviewProvider {
    static var previews: some View {
        CircleImage()
    }
}

ContentView

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        VStack {
            
            VStack(alignment: .leading) {
                
                HStack {
                    Text("タンポポ")
                        .foregroundColor(Color.blue)
                        .font(.title)
                    Text("春の植物")
                }
                
                Text("離弁花類")
            }
        }
    }
    
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

のように別のファイルを用意しています。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?