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!
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

Stephen Hanson
2,030 PointsSwipable 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
39,020 PointsHi 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
2,030 PointsStephen Hanson
2,030 PointsI've added it to the button, How do I get it into code?
Greg Kaleka
39,020 PointsGreg Kaleka
39,020 PointsYou'll need to create an
@IBAction
from thepanGestureRecognizer
into your code.Stephen Hanson
2,030 PointsStephen Hanson
2,030 PointsOK, I'm trying and failing, could you go into more detail on what to do after that?
Greg Kaleka
39,020 PointsGreg Kaleka
39,020 PointsIf 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/