Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target as UIButton to KCFloatingActionButton #3

Closed
navishshanbog opened this issue Dec 8, 2015 · 1 comment
Closed

Add target as UIButton to KCFloatingActionButton #3

navishshanbog opened this issue Dec 8, 2015 · 1 comment

Comments

@navishshanbog
Copy link

Hello Author,

This is definatley not an issue, but I have a question to ask as I am in the learning stage. I would like to know how I can add action to the parent KCFloatingActionButton.
I want to add something like
"button.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)"
to both KCFloatingActionButton and to the KCFloatingActionButtonItem.

Could you please guide me.

Many thanks in advance,

Regards,

@kciter
Copy link
Owner

kciter commented Dec 9, 2015

Hello @navishshanbog,

Unfortunately, KCFloatingActionButton is not UIButton. So, you cannot use addTarget method.
But, if you want to add touch event to KCFloatingActionButton, it is available through UITapGestureRecogonizer.
Below is the sample code.

Swift

let tapGesture = UITapGestureRecognizer(target: self, action: "handleSingleTap:")
self.fab.addGestureRecognizer(tapGesture)

// Event handling method
func handleSingleTap(recognizer: UITapGestureRecognizer) {
  // Do stuff here...
}

Objective-C

UITapGestureRecognizer *tapGesture = 
  [[UITapGestureRecognizer alloc] initWithTarget:self 
                                          action:@selector(handleSingleTap:)];
[self.fab addGestureRecognizer:tapGesture];

// Event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
  // Do stuff here...
}

Best regards,

@kciter kciter closed this as completed Dec 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants