Skip to content

Commit

Permalink
Added blur view properties to public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Oct 6, 2023
1 parent a1e1539 commit 1f10840
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
/// (Default value is 15 points inset from each edge).
@property (nonatomic, assign) UIEdgeInsets contentInset;

/// Replaces the solid color background with a blur view. (Default is NO)
@property (nonatomic, assign) BOOL isBlurBackground;

/// When `isTranslucent` is `YES`, the amount of blur the background view has.
@property (nonatomic, assign) UIBlurEffectStyle blurStyle;

/// The text that is displayed in center of the button (Default is nil).
@property (nonatomic, copy, nullable) IBInspectable NSString *text;

Expand Down
22 changes: 22 additions & 0 deletions TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
_tappedButtonScale = (_tappedButtonScale > FLT_EPSILON) ?: 0.97f;
_tappedTintColorBrightnessOffset = !TO_ROUNDED_BUTTON_FLOAT_IS_ZERO(_tappedTintColorBrightnessOffset) ?: -0.15f;
_contentInset = (UIEdgeInsets){15.0, 15.0, 15.0, 15.0};
_blurStyle = UIBlurEffectStyleDark;
#ifdef __IPHONE_13_0
if (@available(iOS 13.0, *)) { _blurStyle = UIBlurEffectStyleSystemMaterialDark; }
#endif

// Set the tapped tint color if we've set to dynamically calculate it
[self _updateTappedTintColorForTintColor];
Expand Down Expand Up @@ -154,6 +158,24 @@ - (void)_makeTitleLabelIfNeeded TOROUNDEDBUTTON_OBJC_DIRECT {
[_contentView addSubview:_titleLabel];
}

- (UIView *)_makeBackgroundViewWithBlur:(BOOL)withBlur TOROUNDEDBUTTON_OBJC_DIRECT {
UIView *backgroundView = nil;
if (withBlur) {
UIBlurEffect *const blurEffect = [UIBlurEffect effectWithStyle:_blurStyle];
backgroundView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
} else {
backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
}
backgroundView = [[UIView alloc] initWithFrame:self.bounds];
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
backgroundView.backgroundColor = self.tintColor;
backgroundView.layer.cornerRadius = _cornerRadius;
#ifdef __IPHONE_13_0
if (@available(iOS 13.0, *)) { backgroundView.layer.cornerCurve = kCACornerCurveContinuous; }
#endif
return backgroundView;
}

#pragma mark - View Layout -

- (void)layoutSubviews {
Expand Down

0 comments on commit 1f10840

Please sign in to comment.