LearnHow to Create an Animated Button in iOS | Treehouse Quick Tip

Avatar

Amit Bijlani
writes on November 30, 2012

Learn how to create an animated button for your iOS App. Animated buttons are created using the classes UIButton and UIImage. A smooth animation can be achieved by using a series of images animated over a short duration.

The first thing you’ll need a series of images. The names must be named in a numerical sequence so that the number is a suffix to the file name.

To get a smooth animation, simply add more images. These images can be created using any graphics program.

First, add all of your images to the project.

Next, create an IBOutlet for your button.

In your ViewController.m file, refer to your IBOutlet button, and use the setBackgroundImage method using animatedImageName, and provide the file name without the numerical sequence and a duration.

Running the app, you’ll see the animated button repeating.

Similarly, we can create an animation that takes place with the button is touched.

Now you’re ready to add animated button effects to your app!

GET STARTED NOW

Learning with Treehouse for only 30 minutes a day can teach you the skills needed to land the job that you've been dreaming about.

Get Started

Leave a Reply

You must be logged in to post a comment.

man working on his laptop

Are you ready to start learning?

Learning with Treehouse for only 30 minutes a day can teach you the skills needed to land the job that you've been dreaming about.

Start a Free Trial
woman working on her laptop