Skip to content

Commit 1eb8ffa

Browse files
committed
Changed ordering of views when glass is enabled
1 parent 3114150 commit 1eb8ffa

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

TORoundedButton/TORoundedButton.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,18 @@ - (void)setBackgroundStyle:(TORoundedButtonBackgroundStyle)backgroundStyle {
592592
_backgroundStyle = backgroundStyle;
593593
[_backgroundView removeFromSuperview];
594594
_backgroundView = [self _makeBackgroundViewWithStyle:_backgroundStyle];
595-
[_containerView insertSubview:_backgroundView atIndex:0];
596595
_titleLabel.backgroundColor = [self _labelBackgroundColor];
596+
const BOOL isGlass = backgroundStyle == TORoundedButtonBackgroundStyleGlass;
597+
if (!isGlass) {
598+
_containerView.hidden = NO;
599+
[_containerView insertSubview:_backgroundView atIndex:0];
600+
[_containerView addSubview:_contentView];
601+
} else {
602+
UIVisualEffectView *glassView = (UIVisualEffectView *)_backgroundView;
603+
_containerView.hidden = YES;
604+
[self insertSubview:glassView atIndex:0];
605+
[glassView.contentView addSubview:_contentView];
606+
}
597607
[self setNeedsLayout];
598608
}
599609

TORoundedButtonExample/ViewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ - (void)viewDidLoad {
2020
// Hide the tapped label
2121
self.tappedLabel.alpha = 0.0f;
2222

23+
self.button.backgroundStyle = TORoundedButtonBackgroundStyleGlass;
24+
2325
__weak typeof(self) weakSelf = self;
2426
self.button.tappedHandler = ^{
2527
[weakSelf playFadeAnimationOnView:weakSelf.tappedLabel];

0 commit comments

Comments
 (0)