0
1

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 1 year has passed since last update.

【SwiftUI】trimで図形の一部のみを表示させる

Posted at

はじめに

正方形をtrimを使って切り取ってみます。

サンプルアプリ

Simulator Screen Recording - iPhone 15 - 2023-11-13 at 22.50.32.gif

実装

import SwiftUI

struct ContentView: View {
    @State private var trim1: CGFloat = 0
    
    @State private var trim2: CGFloat = 0

    var body: some View {
        VStack {
            Rectangle()
                .trim(from: trim1, to: trim2)
                .frame(width: 300, height: 300)
            
            Slider(value: $trim1, in: 0...1)

            Slider(value: $trim2, in: 0...1)
        }
        .padding()
    }
}

おわり

あんまり使ったことのない機能でした
これ使ってランダムで図形を生成して図形落としゲーム的なの作れるのでは??

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?