

Built-in symbol animations in UIKit controls
source link: https://sarunw.com/posts/built-in-symbol-animations-in-uikit-controls/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Built-in symbol animations in UIKit controls
Table of Contents
In iOS 17, SF Symbols can be animated in various ways.
Some animation effects can use to give feedback and enhance user experiences.
With the coming of new animated symbols, UIKit controls also get a new API to enable animations on some UIControl
.
How to opt-in / out of built-in symbol animations
In iOS 17, Apple added an animation on some UIKit controls.
Some controls have animation enabled by default, e.g., UISlider
.
Some controls have an animation disabled by default, which you can opt-in for it using the new property.
To opt in/out of the built-in animation, we use the new property, isSymbolAnimationEnabled
.
Here is an example of built-in animation for UIButton
, UIBarButtonItem
, and UISlider
.
var conf = UIButton.Configuration.plain()
conf.title = "Add"
conf.image = UIImage(systemName: "plus.app")
let animateButton = UIButton(configuration: conf)
animateButton.isSymbolAnimationEnabled = true
let barButtonItem = UIBarButtonItem(title: "Add", image: UIImage(systemName: "plus.app"), primaryAction: nil, menu: nil)
navigationItem.rightBarButtonItem = barButtonItem
barButtonItem.isSymbolAnimationEnabled = true
let slider = UISlider()
slider.minimumValueImage = UIImage(systemName: "tortoise")
slider.maximumValueImage = UIImage(systemName: "hare")
We explicitly set isSymbolAnimationEnabled
to true
for UIButton
and UIBarButton
because the animation is disabled by default for those controls.
But it is enabled by default for UISlider
, so you don't need to set it.

You can easily support sarunw.com by checking out this sponsor.

SwiftUI
It is quite surprising to me that this feature is exclusive to UIKit.
Apple doesn't expose the same API for SwiftUI.
Some control in SwiftUI also got this nice animation, e.g., Slider
. But you can't opt out of that animation.
I tried using .symbolEffectsRemoved()
, but it doesn't work.
Slider(value: $speed) {
Text("Speed")
} minimumValueLabel: {
Image(systemName: "tortoise")
} maximumValueLabel: {
Image(systemName: "hare")
}
.symbolEffectsRemoved()
And there is no modifier to enable an animation on the SwiftUI button either.
Read more article about UIKit, iOS 17,
or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
SwiftUI Plain Button Style cannot tap on an Empty space
The plain button style has behavior and appearance different from the other styles. Let's learn how this affects a tappable area.
How to use NSAttributedString in SwiftUI
Learn how to use an old NSAttributedString inside a SwiftUI app.
Recommend
-
44
At the current state of SwiftUI not all views are implemented yet. UIKit views can be added in the Swift hierarchy. In this tutorial a url will be displayed in a web view.SwiftUI requires Xcode 11 and MacOS Catalina, for...
-
28
A few weeks ago, we talked about building views like PagerView and BottomSheetView from scratch in SwiftUI . SwiftUI is pretty young and misses some components that we expect to hav...
-
16
Creating animations with UIKit and Core Animation We, developers, have a lot of options when it comes to animations nowadays. There is plenty of libraries that can be used to easily integrate an animation prepare...
-
27
一、背景 随着 Flutter 的出现,UI 开发形式也越来越趋向相同,Flutter,SwiftUI,RN,Weex 等新兴 UI 框架无一意外都使用了声明式的 UI 开发模式,和支持了 FlexBox 的布局系统。 FlexBox 自从被 W3C 提出之后,就被...
-
8
Stack Views Introduction 2:54 Free...
-
20
咱们最有意思的第四篇 SwiftUI 教程来啦!为什么说是“最有意思”的呢?因为按照约定,在这篇文章里我们会一起来看看用 SwiftUI 开发界面的快捷便利体现在什么地方。相信这会让许多苹果开发者们耳目一新。 信了苹果教之后,每次有什么更新,...
-
10
在上一篇文章中,我们了解了 SwiftUI 的 Text 组件,并通过 Stack 系列的组件对内容进行了一些简单的布局。在这篇文章里,我们会认识一个全新的图片组件...
-
6
dHealth Network built on Symbol aims to empower e-health – HodlalertdHealth Network built on Symbol aims to empower e-health
-
4
animation-wrapper-view, declarative animations with imperative controls Aug 25 ・1 min read...
-
9
light up my life — Windows 11 could replace bad gamer apps with built-in RGB lighting controls Your gaming PC can be obnoxious, but your software shouldn't have to be....
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK