Skip to content

Commit

Permalink
Merge pull request #46 from TimOliver/delegate
Browse files Browse the repository at this point in the history
Added a delegate property to receive button tap events
  • Loading branch information
TimOliver authored Oct 8, 2023
2 parents d34fa77 + 1a2509e commit 2ea8628
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 2ea8628

Please sign in to comment.