7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qiita全国学生対抗戦Advent Calendar 2023

Day 6

【SwiftUI】画像をShapeStyleとして使いたい

Posted at

はじめに

図形にforgroundStyleで画像をのせたいことがありました。
できるのかなと調べたところ出来そうだったので記事にしておきます。

素材

gradation.png

サンプルアプリ

simulator_screenshot_1F031802-7025-43D1-9749-33507E7EC232.png

実装

ImagePaintを使用してShapeStyle化できるっぽいです。
引数はimageの他にscaleやsourceRectなどがあります。

import SwiftUI

struct ContentView: View {
    var body: some View {
        Circle()
            .foregroundStyle(ImagePaint(image: Image(.gradation)))
    }
}

おわり

ImagePaintなんて使ったことなかったです

公式ドキュメント

7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?