Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Stephen Hanson
Stephen Hanson
2,030 Points

Swipable Buttons?

Im creating a calculator app and would like to make a multi function button. One where you could swipe up or down for alternate functionality. How would i do that. Also, when you swipe up or down, the title should change as well.

Thanks

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Stephen,

You could accomplish this by adding a panGestureRecognizer to your button (the easiest way to do this would be to do it in interface builder). Then you would link it to an @IBAction in your code, where you would determine the direction of the swipe, and do some calculation and/or change the text on the button.

Let me know if this gives you enough to get started!

Stephen Hanson
Stephen Hanson
2,030 Points

I've added it to the button, How do I get it into code?

Greg Kaleka
Greg Kaleka
39,021 Points

You'll need to create an @IBAction from the panGestureRecognizer into your code.

Stephen Hanson
Stephen Hanson
2,030 Points

OK, I'm trying and failing, could you go into more detail on what to do after that?

Greg Kaleka
Greg Kaleka
39,021 Points

If you can get more specific with what you're having trouble with, I might be able to help.

Take a look at this tutorial, which includes more or less exactly what you're looking for, I think: http://www.avocarrot.com/blog/implement-gesture-recognizers-swift/