当前位置:网站首页>Swiftui creates a beautiful custom press feedback button

Swiftui creates a beautiful custom press feedback button

2022-06-30 07:13:00 Giant panda Hou Pei

 Insert picture description here



functional requirement

Sometimes , We need to be in SwiftUI Create an impressive button for user interaction , Like this one down here :

 Insert picture description here

As shown in the figure above , We give users a colorful feedback effect after continuously pressing the view , I can't help but brighten my eyes .

How is this achieved ?

Actually , It's not as hard as you think !

So, What are you waiting for ?

Let‘s go!



Functional analysis

1. Getting the pressed state of the button is the key

In order to get different feedback effects according to the button pressing state , We first need a way to get the button pressed .

If you have implemented custom button styles , Then I will never forget Configuration.isPressed attribute .

This is exactly what we need !

1.1 Use the binding to pass the press state

struct HyButtonPressingStyle:
原网站

版权声明
本文为[Giant panda Hou Pei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/181/202206300710237261.html