@@ -732,6 +732,9 @@ - (CGSize)intrinsicContentSize {
732732 }
733733 CGSize clampToMinimumSize = [self clampToMinimumSize: size];
734734 if (_buttonSizeSet) {
735+ if (@available (iOS 15.0 , *)) {
736+ size = [self explicitSize ];
737+ }
735738 _visualContentSize = size;
736739 return CGSizeMake (MAX (kMinimumTouchTarget , clampToMinimumSize.width ),
737740 MAX (kMinimumTouchTarget , clampToMinimumSize.height ));
@@ -750,6 +753,9 @@ - (CGSize)sizeThatFits:(CGSize)size {
750753 CGSize clampToMinimumSize = [self clampToMinimumSize: newSize];
751754 [self setCapsuleCornersBasedOn: clampToMinimumSize];
752755 if (_buttonSizeSet) {
756+ if (@available (iOS 15.0 , *)) {
757+ newSize = [self explicitSize ];
758+ }
753759 _visualContentSize = newSize;
754760 return CGSizeMake (MAX (kMinimumTouchTarget , clampToMinimumSize.width ),
755761 MAX (kMinimumTouchTarget , clampToMinimumSize.height ));
@@ -758,6 +764,36 @@ - (CGSize)sizeThatFits:(CGSize)size {
758764 }
759765}
760766
767+ - (CGSize)explicitSize API_AVAILABLE(ios(15.0 )) {
768+ [self updateInsets ];
769+ BOOL hasTitle = self.currentTitle .length > 0 || self.currentAttributedTitle .length > 0 ;
770+ BOOL hasImage = self.currentImage != nil ;
771+ CGSize size = [super intrinsicContentSize ];
772+ CGFloat imageEdgeInsetsWidth = self.imageEdgeInsets .left + self.imageEdgeInsets .right ;
773+ CGFloat contentEdgeInsetsWidth = self.contentEdgeInsets .left + self.contentEdgeInsets .right ;
774+ CGFloat imageEdgeInsetsHeight = self.imageEdgeInsets .top + self.imageEdgeInsets .bottom ;
775+ CGFloat contentEdgeInsetsHeight = self.contentEdgeInsets .top + self.contentEdgeInsets .bottom ;
776+ CGFloat symbolSize = _symbolFonts[@(self .buttonSize)].pointSize ;
777+ if (hasTitle && hasImage) {
778+ CGFloat iconWidth = imageEdgeInsetsWidth + symbolSize;
779+ CGFloat titleWidth = contentEdgeInsetsWidth + self.titleLabel .intrinsicContentSize .width ;
780+ CGFloat iconHeight = imageEdgeInsetsHeight + symbolSize;
781+ CGFloat titleHeight = contentEdgeInsetsHeight + self.titleLabel .intrinsicContentSize .height ;
782+ size = CGSizeMake (iconWidth + titleWidth, MAX (iconHeight, titleHeight));
783+ } else if (hasImage) {
784+ // If only using an image we set the contentEdgeInsets rather than imageEdgeInsets.
785+ CGFloat width = contentEdgeInsetsWidth + symbolSize;
786+ CGFloat height = contentEdgeInsetsHeight + symbolSize;
787+ size = CGSizeMake (width, height);
788+ } else if (hasTitle) {
789+ CGFloat width = contentEdgeInsetsWidth + self.titleLabel .intrinsicContentSize .width ;
790+ CGFloat height = contentEdgeInsetsHeight + self.titleLabel .intrinsicContentSize .height ;
791+ size = CGSizeMake (width, height);
792+ }
793+
794+ return size;
795+ }
796+
761797#pragma mark - CALayerDelegate
762798
763799- (nullable id <CAAction >)actionForLayer : (CALayer *)layer forKey : (NSString *)key {
0 commit comments