6
5

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] Imageの使い方

Last updated at Posted at 2019-11-29

SwiftUI Imageの使い方

// ViewにImageを表示する
var body: some View {
    Image("image-name")
}

// SF Symbols アイコンの使い方
// https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/
Image(systemName: "icon-name")

// SF Symbols アイコンの使う場合は色も変更できる
Image(systemName: "icon-name")
     .foregroundColor(.blue)

// サイズ調整
Image(systemName: "icon-name")
     .resizable()

// 幅や高さの設定
Image(systemName: "icon-name")
     .aspectRatio(contentMode: .fill)

// UIImageを使う場合
guard let img = UIImage(named: "image-name") else {
    fatalError("Fail to load image")
}

// グラデーション
Text("SwiftUI")
    .background(LinearGradient(gradient: Gradient(colors: [.white, .black]), startPoint: .top, endPoint: .bottom), cornerRadius: 1)

// 図形
Rectangle()
    .fill(Color.red)
    .frame(width: 50, height: 50)

Circle()
    .fill(Color.blue)
    .frame(width: 100, height: 100)

// 背景イメーシ
Text("SwiftUI")
    .background(
        Image("image-name")
            .resizable()
            .frame(width: 100, height: 100))
6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?