Skip to content
This repository was archived by the owner on Dec 11, 2025. It is now read-only.

Commit f7ef737

Browse files
codeman7material-automation
authored andcommitted
#Buttons Fix bug where background would be in front of other elements.
PiperOrigin-RevId: 752334470
1 parent a801760 commit f7ef737

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

components/M3CButton/src/M3CButton.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,16 @@ - (void)setImage:(nullable UIImage *)image forState:(UIControlState)state {
547547
}
548548
}
549549

550+
- (void)didMoveToSuperview {
551+
[super didMoveToSuperview];
552+
553+
// If the image or title are set before the button is part of the heirarchy, then the visual
554+
// background will be on top of the image or title.
555+
if (_buttonSizeSet) {
556+
[self sendSubviewToBack:self.visualBackground];
557+
}
558+
}
559+
550560
- (void)traitCollectionDidChange:(nullable UITraitCollection *)previousTraitCollection {
551561
[super traitCollectionDidChange:previousTraitCollection];
552562
[self updateCGColors];

0 commit comments

Comments
 (0)