0

Inside of a VC, I'm trying to figure out how to have a UIButton recognize a horizontal swipe and then tap.

There is an array of text.

var plotList = ["stuff", "to do", "this", "or that"]

default display is plotList[0].

the carousel repeats in an infinite loop doesn't stop at the end of the array.

as user swipes over button only, i don't want the other components of the VC to react to this particular swipe, i want the button to display the plotList string.

when the user taps on the button, i want to shove the result into a switch that will launch the appropriate UIView.

i'd like to avoid doing this UILabel/UIButton combination. See Handling Touch Event in UILabel and hooking it up to an IBAction.

so far i'm here

import UIKit

class carouselVC: UIViewController {


  @IBOutlet var carouselView: UIView!
  @IBOutlet var labelOutlet: UILabel!
  @IBOutlet var buttonOutlet: UIButton!

  var plotList = ["stuff", "this", "that"]

  let swipeRec = UISwipeGestureRecognizer()


  override func viewDidLoad() {
    super.viewDidLoad()
    var swipeButtonLeft: UISwipeGestureRecognizer =
    UISwipeGestureRecognizer(target: self, action: "buttonLeft")
    swipeButtonLeft.direction = UISwipeGestureRecognizerDirection.Left
    self.buttonOutlet.addGestureRecognizer(swipeButtonLeft)

    var swipeButtonRight: UISwipeGestureRecognizer =
    UISwipeGestureRecognizer(target: self, action: "buttonRight")
    swipeButtonRight.direction = UISwipeGestureRecognizerDirection.Right
    self.buttonOutlet.addGestureRecognizer(swipeButtonRight)

  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

  func buttonLeft(){
    println("buttonLeft")
  }
  func buttonRight(){
    println("buttonRight")
  }

  @IBAction func buttonAction(sender: UIButton) {
    sender.setTitle(plotList[1], forState: .Normal)
  }
}

any help?

Community
  • 1
  • 1
  • I've been hacking through this example and think i need to Frankenstein something like this `http://stackoverflow.com/questions/28059381/adding-gestures-to-a-button-in-swift` – μολὼν.λαβέ Feb 10 '15 at 21:45

1 Answers1

1

Use a UIView with a UILabel, instead of button. Add UIView over UILabel and make it clear color. You may make UIlabel look like a button. Add a swipe gesture/tap gesture on it. And do any operation in the action of the gestures.

MasterGoGo
  • 98
  • 6