Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Adds customisation for button: corner radius, border color, border width #305

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion Source/UIScrollView+EmptyDataSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -281,3 +305,4 @@ NS_ASSUME_NONNULL_BEGIN
#undef DZNEmptyDataSetDeprecated

NS_ASSUME_NONNULL_END

51 changes: 51 additions & 0 deletions Source/UIScrollView+EmptyDataSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:)]) {
Expand Down Expand Up @@ -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]];
}
}

Expand Down