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

可変のSF Symbolsを使いこなす

Posted at

値によって塗りつぶされ具合が変わるシンボルがちょこちょこあるので、これを使ってアニメーションを作ってみる

10%
image.png

80%
image.png

ImageにvariableValueを渡すと、可変シンボルであれば、その数値によって塗りつぶされ具合が変わってくれる

import SwiftUI

struct Hoge: View {
    var body: some View {
        Image(systemName: "timelapse", variableValue: 0.2)
            .imageScale(.large)
            .font(.system(size: 200))
    }
}

struct Modal_Previews: PreviewProvider {
    static var previews: some View {
        Hoge()
    }
}

image.png

あとはこの数値を時間経過で増減させればOK

import SwiftUI

struct Hoge: View {
    @State var time = 0.0
    let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect()
    
    var body: some View {
        Image(systemName: "timelapse", variableValue: time)
            .imageScale(.large)
            .font(.system(size: 200))
            .onReceive(timer) { value in
                if time < 1.0 {
                    time += 0.1
                } else {
                    time = 0.0
                }
            }
    }
}

struct Modal_Previews: PreviewProvider {
    static var previews: some View {
        Hoge()
    }
}

download.gif

3
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
3
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?