6.1 C
Canberra
Friday, October 24, 2025

Utilizing SymbolEffect to Animate SF Symbols in iOS 17


In terms of designing visually interesting and intuitive consumer interfaces in iOS improvement, SF Symbols are a useful asset. It gives a complete library of over 5,000 customizable icons, designed particularly for iOS and macOS functions. The newest iOS 17 replace brings SF Symbols 5, which introduces a unbelievable assortment of expressive animations. SwiftUI gives builders the flexibility to leverage these animations utilizing the brand new symbolEffect modifier.

This function empowers builders to create numerous and fascinating animations inside their apps. By incorporating symbolEffect into your SwiftUI code, builders can improve consumer interactions and create visually partaking interfaces. On this tutorial, we are going to present you easy methods to work with this new modifier to create varied sorts of animations.

The Fundamental Utilization of SymbolEffect

To animate a SF image, you’ll be able to connect the brand new symbolEffect modifier to the Picture view and specify the specified animation kind. Right here is an instance:

struct ContentView: View {
    @State non-public var animate = false

    var physique: some View {
        Picture(systemName: "ellipsis.message")
            .font(.system(dimension: 100))
            .symbolRenderingMode(.palette)
            .foregroundStyle(.purple, .grey)
            .symbolEffect(.bounce, worth: animate)
            .onTapGesture {
                animate.toggle()
            }
    }
}

There are a variety of built-in animations together with Seem, Disappear, Bounce, Scale, Pulse, Variable Colour, and Exchange. Within the code above, we use the bounce animation. So, whenever you faucet the image within the preview canvas, it reveals a bouncing impact.

symboleffect-demo

Make it Repeatable

By default, the animation is simply performed as soon as. To make it repeatable, you’ll be able to set the choices parameter of the modifier to .repeating like this:

.symbolEffect(.bounce, choices: .repeating, worth: animate)

This can obtain an animated impact that repeats indefinitely. Should you need to repeat the impact for a particular variety of occasions, you’ll be able to make the most of the .repeat perform and point out the specified repeat rely as proven beneath:

.symbolEffect(.bounce, choices: .repeat(5), worth: animate)

Controlling the animation velocity

swiftui-symboleffect-speed

As well as, you have got the flexibleness to customise the animation velocity by using the .velocity perform throughout the choices parameter. For example, in case you want to decelerate the animation, you’ll be able to set the worth of the .velocity perform to 0.1, as demonstrated beneath:

.symbolEffect(.bounce, choices: .velocity(0.1), worth: animate)

Animation Varieties

As said earlier, SwiftUI gives a wide range of built-in animation sorts, similar to Bounce, Scale, Pulse, Variable Colour, and Exchange. Up till now, we have now completely used the bounce animation. Now, let’s discover and check out different animation sorts utilizing the supplied code snippet:

struct SymbolAnimationView: View {
    @State non-public var animate = false

    var physique: some View {
        VStack(alignment: .main, spacing: 50) {
            HStack {
                Picture(systemName: "mic.and.sign.meter")
                    .font(.system(dimension: 60))
                    .symbolRenderingMode(.palette)
                    .foregroundStyle(.purple, .grey)
                    .symbolEffect(.bounce, choices: .repeating, worth: animate)
                Textual content("Bounce")
                    .font(.largeTitle)
            }

            HStack {
                Picture(systemName: "mic.and.sign.meter")
                    .font(.system(dimension: 60))
                    .symbolRenderingMode(.palette)
                    .foregroundStyle(.purple, .grey)
                    .symbolEffect(.bounce.down, choices: .repeating, worth: animate)
                Textual content("Bounce (down)")
                    .font(.largeTitle)
            }

            HStack {
                Picture(systemName: "mic.and.sign.meter")
                    .font(.system(dimension: 60))
                    .symbolRenderingMode(.palette)
                    .foregroundStyle(.purple, .grey)
                    .symbolEffect(.pulse, choices: .repeating, worth: animate)
                Textual content("Pulse")
                    .font(.largeTitle)
            }

            HStack {
                Picture(systemName: "mic.and.sign.meter")
                    .font(.system(dimension: 60))
                    .symbolRenderingMode(.palette)
                    .foregroundStyle(.purple, .grey)
                    .symbolEffect(.pulse.wholeSymbol, choices: .repeating, worth: animate)
                Textual content("Pulse (entire)")
                    .font(.largeTitle)
            }

            HStack {
                Picture(systemName: "mic.and.sign.meter")
                    .font(.system(dimension: 60))
                    .symbolRenderingMode(.palette)
                    .foregroundStyle(.purple, .grey)
                    .symbolEffect(.variableColor, choices: .repeating, worth: animate)
                Textual content("Variable shade")
                    .font(.largeTitle)
            }

        }
        .onTapGesture {
            animate.toggle()
        }
    }
}

By tapping any of the pictures within the preview canvas, you’ll be able to see the animations coming to life. Compared to the bounce animation, the Pulse animation gives a definite impact by step by step fading the opacity of particular or all layers throughout the picture. Then again, the variableColor animation replaces the opacity of variable layers within the picture, offering a singular visible transformation.

swiftui-symboleffect-animations

Even for the Bounce animation, you’ll be able to specify .bounce.down to bounce the image downward.

.symbolEffect(.bounce.down, choices: .repeating, worth: animate)

For added flexibility, it’s potential to use a number of symbolEffect modifiers to a view, permitting you to realize a customized impact by combining totally different animations.

Picture(systemName: "ellipsis.message")
    .font(.system(dimension: 100))
    .symbolRenderingMode(.palette)
    .foregroundStyle(.purple, .grey)
    .symbolEffect(.bounce, choices: .velocity(1.5), worth: animate)
    .symbolEffect(.pulse, choices: .repeating, worth: animate)
    .onTapGesture {
        animate.toggle()
    }

Content material Transition and Exchange Animation

symboleffect-content-transition

In sure eventualities, there could also be a have to transition between totally different symbols inside a picture. For example, when a consumer faucets the Contact ID image, it transforms right into a checkmark image. To make sure a seamless and visually pleasing transition, you’ll be able to make the most of the contentTransition modifier together with the Exchange animation, as demonstrated beneath:

Picture(systemName: animate ? "checkmark.circle" : "touchid")
    .font(.system(dimension: 100))
    .symbolRenderingMode(.palette)
    .symbolEffect(.bounce, worth: animate)
    .contentTransition(.symbolEffect(.change))
    .foregroundStyle(.purple, .grey)
    .onTapGesture {
        animate.toggle()
    }

Abstract

SF Symbols and symbolEffect present builders with highly effective instruments to boost consumer interactions and create visually partaking interfaces in iOS and macOS functions.

This tutorial demonstrates the essential utilization of symbolEffect, making animations repeatable, controlling animation velocity, and exploring totally different animation sorts. It additionally covers content material transition and change animation.

You probably have discovered this tutorial gratifying and wish to discover SwiftUI additional, we extremely suggest trying out our complete ebook, “Mastering SwiftUI.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles