diff --git a/Source/UIScrollView+EmptyDataSet.h b/Source/UIScrollView+EmptyDataSet.h index ddd45aa3..8b4b05f6 100644 --- a/Source/UIScrollView+EmptyDataSet.h +++ b/Source/UIScrollView+EmptyDataSet.h @@ -88,7 +88,7 @@ NS_ASSUME_NONNULL_BEGIN * * @return image animation */ -- (nullable CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView; +- (nullable CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; /** Asks the data source for the title to be used for the specified button state. @@ -155,6 +155,30 @@ NS_ASSUME_NONNULL_BEGIN */ - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView; +/** + Asks the data source for the button's border width. Default is 0. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's border width. + */ +- (CGFloat)buttonBorderWidthForEmptyDataSet:(UIScrollView *)scrollView; + +/** + Asks the data source for the color of the border. Default is clear. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's border color. + */ +- (CGColorRef)buttonBorderColorForEmptyDataSet:(UIScrollView *)scrollView; + +/** + Asks the data source for the corner radius of the button. Default is 0. + + @param scrollView A scrollView subclass object informing the delegate. + @return The button's corner radius. + */ +- (CGFloat)buttonBorderCornerRadiusForEmptyDataSet:(UIScrollView *)scrollView; + @end @@ -281,3 +305,4 @@ NS_ASSUME_NONNULL_BEGIN #undef DZNEmptyDataSetDeprecated NS_ASSUME_NONNULL_END + diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index ce43ffcd..6b8fb166 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -245,6 +245,33 @@ - (UIImage *)dzn_buttonBackgroundImageForState:(UIControlState)state return nil; } +- (CGFloat)dzn_buttonBorderWidth { + CGFloat width = 0.0; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderWidthForEmptyDataSet:)]) + width = [self.emptyDataSetSource buttonBorderWidthForEmptyDataSet:self]; + + return width; +} + +- (CGColorRef)dzn_buttonBorderColor { + CGColorRef color = [UIColor clearColor].CGColor; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderColorForEmptyDataSet:)]) + color = [self.emptyDataSetSource buttonBorderColorForEmptyDataSet:self]; + + return color; +} + +- (CGFloat)dzn_buttonCornerRadius { + CGFloat radius = 0.0; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(buttonBorderCornerRadiusForEmptyDataSet:)]) + radius = [self.emptyDataSetSource buttonBorderCornerRadiusForEmptyDataSet:self]; + + return radius; +} + - (UIColor *)dzn_dataSetBackgroundColor { if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(backgroundColorForEmptyDataSet:)]) { @@ -513,6 +540,30 @@ - (void)dzn_reloadEmptyDataSet [view.button setAttributedTitle:[self dzn_buttonTitleForState:UIControlStateHighlighted] forState:UIControlStateHighlighted]; [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:UIControlStateNormal] forState:UIControlStateNormal]; [view.button setBackgroundImage:[self dzn_buttonBackgroundImageForState:UIControlStateHighlighted] forState:UIControlStateHighlighted]; + + view.button.layer.masksToBounds = YES; + [view.button sizeToFit]; + + [view.button addConstraint:[NSLayoutConstraint constraintWithItem:view.button + attribute:NSLayoutAttributeWidth + relatedBy:NSLayoutRelationEqual + toItem:nil + attribute:NSLayoutAttributeNotAnAttribute + multiplier:1 + constant:view.button.frame.size.width + 60]]; + + [view.contentView addConstraint:[NSLayoutConstraint constraintWithItem:view.button + attribute:NSLayoutAttributeCenterX + relatedBy:NSLayoutRelationEqual + toItem:view.contentView + attribute:NSLayoutAttributeCenterX + multiplier:1 + constant:0]]; + + view.button.layer.borderWidth = [self dzn_buttonBorderWidth]; + view.button.layer.borderColor = [self dzn_buttonBorderColor]; + view.button.layer.cornerRadius = [self dzn_buttonCornerRadius]; + view.button.tintColor = [UIColor colorWithCGColor:[self dzn_buttonBorderColor]]; } }