diff --git a/Toast/Example/CSViewController.m b/Toast/Example/CSViewController.m index 990c542..f07cdb3 100644 --- a/Toast/Example/CSViewController.m +++ b/Toast/Example/CSViewController.m @@ -32,6 +32,7 @@ @interface CSViewController () @property (assign, nonatomic, getter=isShowingActivity) BOOL showingActivity; +@property (assign, nonatomic, getter=isShowingActivityWithCustomStyle) BOOL showingActivityWithCustomStyle; @end @@ -44,6 +45,7 @@ - (instancetype)initWithStyle:(UITableViewStyle)style { if (self) { self.title = @"Toast"; self.showingActivity = NO; + self.showingActivityWithCustomStyle = NO; } return self; } @@ -81,7 +83,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger if (section == 0) { return 2; } else { - return 9; + return 10; } } @@ -156,6 +158,8 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.textLabel.text = @"Show an image as toast at point\n(110, 110)"; } else if (indexPath.row == 8) { cell.textLabel.text = (self.isShowingActivity) ? @"Hide toast activity" : @"Show toast activity"; + } else if (indexPath.row == 9) { + cell.textLabel.text = (self.isShowingActivityWithCustomStyle) ? @"Hide toast activity with a custom style" : @"Show toast activity with a custom style"; } return cell; @@ -267,6 +271,18 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath } _showingActivity = !self.isShowingActivity; + [tableView reloadData]; + } else if (indexPath.row == 9) { + // Make toast activity + if (!self.isShowingActivityWithCustomStyle) { + CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; + style.backgroundColor = nil; + [self.navigationController.view makeToastActivity:CSToastPositionCenter style:style indicatorStyle:UIActivityIndicatorViewStyleGray]; + } else { + [self.navigationController.view hideToastActivity]; + } + _showingActivityWithCustomStyle = !self.isShowingActivityWithCustomStyle; + [tableView reloadData]; } } diff --git a/Toast/Toast/UIView+Toast.h b/Toast/Toast/UIView+Toast.h index 018e23d..4430875 100644 --- a/Toast/Toast/UIView+Toast.h +++ b/Toast/Toast/UIView+Toast.h @@ -158,6 +158,39 @@ extern const NSString * CSToastPositionBottom; */ - (void)makeToastActivity:(id)position; +/** + Creates and displays a new toast activity indicator view at a specified position. + + @warning Only one toast activity indicator view can be presented per superview. Subsequent + calls to `makeToastActivity:` will be ignored until hideToastActivity is called. + + @warning `makeToastActivity:` works independently of the showToast: methods. Toast activity + views can be presented and dismissed while toast views are being displayed. `makeToastActivity:` + has no effect on the queueing behavior of the showToast: methods. + + @param position The toast's center point. Can be one of the predefined CSToastPosition + constants or a `CGPoint` wrapped in an `NSValue` object. + @param style The style. The shared style will be used when nil + */ +- (void)makeToastActivity:(id)position style: (CSToastStyle *)style; + +/** + Creates and displays a new toast activity indicator view at a specified position. + + @warning Only one toast activity indicator view can be presented per superview. Subsequent + calls to `makeToastActivity:` will be ignored until hideToastActivity is called. + + @warning `makeToastActivity:` works independently of the showToast: methods. Toast activity + views can be presented and dismissed while toast views are being displayed. `makeToastActivity:` + has no effect on the queueing behavior of the showToast: methods. + + @param position The toast's center point. Can be one of the predefined CSToastPosition + constants or a `CGPoint` wrapped in an `NSValue` object. + @param style The style. The shared style will be used when nil + @param indicatorStyle The UIActivatyIndicatorViewStyle. + */ +- (void)makeToastActivity:(id)position style:(CSToastStyle *)style indicatorStyle:(UIActivityIndicatorViewStyle)indicatorStyle; + /** Dismisses the active toast activity indicator view. */ diff --git a/Toast/Toast/UIView+Toast.m b/Toast/Toast/UIView+Toast.m index f31a459..993e5c7 100644 --- a/Toast/Toast/UIView+Toast.m +++ b/Toast/Toast/UIView+Toast.m @@ -354,11 +354,21 @@ - (void)cs_handleToastTapped:(UITapGestureRecognizer *)recognizer { #pragma mark - Activity Methods - (void)makeToastActivity:(id)position { + [self makeToastActivity:position style:nil]; +} + +- (void)makeToastActivity:(id)position style:(CSToastStyle *)style { + [self makeToastActivity:position style:style indicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; +} + +- (void)makeToastActivity:(id)position style:(CSToastStyle *)style indicatorStyle:(UIActivityIndicatorViewStyle)indicatorStyle { // sanity UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey); if (existingActivityView != nil) return; - CSToastStyle *style = [CSToastManager sharedStyle]; + if (style == nil) { + style = [CSToastManager sharedStyle]; + } UIView *activityView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, style.activitySize.width, style.activitySize.height)]; activityView.center = [self cs_centerPointForPosition:position withToast:activityView]; @@ -374,7 +384,7 @@ - (void)makeToastActivity:(id)position { activityView.layer.shadowOffset = style.shadowOffset; } - UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; + UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:indicatorStyle]; activityIndicatorView.center = CGPointMake(activityView.bounds.size.width / 2, activityView.bounds.size.height / 2); [activityView addSubview:activityIndicatorView]; [activityIndicatorView startAnimating]; @@ -392,6 +402,8 @@ - (void)makeToastActivity:(id)position { } completion:nil]; } + + - (void)hideToastActivity { UIView *existingActivityView = (UIView *)objc_getAssociatedObject(self, &CSToastActivityViewKey); if (existingActivityView != nil) {