Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom contant frame size #839

Open
wants to merge 2 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
4 changes: 4 additions & 0 deletions SVProgressHUD/SVProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef void (^SVProgressHUDDismissCompletion)(void);
@property (assign, nonatomic) NSTimeInterval graceTimeInterval; // default is 0 seconds
@property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds
@property (assign, nonatomic) NSTimeInterval maximumDismissTimeInterval; // default is CGFLOAT_MAX
@property (assign, nonatomic) CGFloat maximumFrameWidth; // default is 200
@property (assign, nonatomic) CGFloat maximumFrameHeight; // default is 300

@property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0

Expand Down Expand Up @@ -107,6 +109,8 @@ typedef void (^SVProgressHUDDismissCompletion)(void);
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
+ (void)setMaximumFrameWidth:(CGFloat)newWidth; // default is 200
+ (void)setMaximumFrameHeight:(CGFloat)newHeight; // default is 300

#pragma mark - Show Methods

Expand Down
13 changes: 12 additions & 1 deletion SVProgressHUD/SVProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ + (void)setHapticsEnabled:(BOOL)hapticsEnabled {
[self sharedView].hapticsEnabled = hapticsEnabled;
}

+ (void)setMaximumFrameWidth:(CGFloat)newWidth {
[self sharedView].maximumFrameWidth = newWidth;
}

+ (void)setMaximumFrameHeight:(CGFloat)newHeight {
[self sharedView].maximumFrameHeight = newHeight;
}

#pragma mark - Show Methods

+ (void)show {
Expand Down Expand Up @@ -410,6 +418,9 @@ - (instancetype)initWithFrame:(CGRect)frame {
_graceTimeInterval = 0.0f;
_minimumDismissTimeInterval = 5.0;
_maximumDismissTimeInterval = CGFLOAT_MAX;

_maximumFrameWidth = 200.0;
_maximumFrameHeight = 300.0;

_fadeInAnimationDuration = SVProgressHUDDefaultAnimationDuration;
_fadeOutAnimationDuration = SVProgressHUDDefaultAnimationDuration;
Expand Down Expand Up @@ -438,7 +449,7 @@ - (void)updateHUDFrame {
CGFloat labelWidth = 0.0f;

if(self.statusLabel.text) {
CGSize constraintSize = CGSizeMake(200.0f, 300.0f);
CGSize constraintSize = CGSizeMake(self.maximumFrameWidth, self.maximumFrameHeight);
labelRect = [self.statusLabel.text boundingRectWithSize:constraintSize
options:(NSStringDrawingOptions)(NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin)
attributes:@{NSFontAttributeName: self.statusLabel.font}
Expand Down