Skip to content

Commit

Permalink
Added a delegate property to receive button tap events
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Oct 8, 2023
1 parent d34fa77 commit 1a2509e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ x.y.z Release Notes (yyyy-MM-dd)

### Added

* A `delegate` property to receive tap events for the button where delegates are preferred over blocks.
* An `isTranslucent` property (and a `blurStyle` property) that replaces the background of buttons from a solid color to a blurred background.
* A `contentView` property to enable adding custom view content to buttons.
* `sizeToFit` and `sizeThatFits:` methods to allow automatic sizing of buttons around their content.
Expand Down
13 changes: 13 additions & 0 deletions TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@

NS_ASSUME_NONNULL_BEGIN

@class TORoundedButton;

@protocol TORoundedButtonDelegate <NSObject>

/// Called when the user taps on the associated button.
/// - Parameter button: The button object that was tapped.
- (void)roundedButtonDidTap:(TORoundedButton *)button;

@end

NS_SWIFT_NAME(RoundedButton)
IB_DESIGNABLE @interface TORoundedButton : UIControl

/// A delegate object that can receive tap events from this button.
@property (nonatomic, weak) id<TORoundedButtonDelegate> delegate;

/// The radius of the corners of this button (Default is 12.0f).
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;

Expand Down
3 changes: 2 additions & 1 deletion TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,9 @@ - (void)_didTouchUpInside {
// Send the semantic button action for apps relying on this action
[self sendActionsForControlEvents:UIControlEventPrimaryActionTriggered];

// Trigger the block if it has been set
// Broadcast the tap event to all subscribed objects.
if (self.tappedHandler) { self.tappedHandler(); }
[_delegate roundedButtonDidTap:self];
}

- (void)_didDragOutside {
Expand Down

0 comments on commit 1a2509e

Please sign in to comment.