Skip to content

Commit b56ec3c

Browse files
committed
- Add Indeterminate progress
1 parent 01956c0 commit b56ec3c

7 files changed

Lines changed: 79 additions & 5 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Animated Alert View written in Swift but ported to Objective-C, which can be use
1010
![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot2.png)
1111
![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot3.png)
1212
![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot4.png)
13+
![BackgroundImage](https://raw.githubusercontent.com/dogo/SCLAlertView/master/ScreenShots/ScreenShot5.png)
1314

1415
###Easy to use
1516
```Objective-C
@@ -98,6 +99,14 @@ UITextField *textField = [alert addTextField:@"Enter your name"];
9899
[alert showEdit:self title:@"Edit View" subTitle:@"This alert view shows a text box" closeButtonTitle:@"Done" duration:0.0f];
99100
```
100101
102+
###Indeterminate progress
103+
```Objective-C
104+
SCLAlertView *alert = [[SCLAlertView alloc] init];
105+
106+
[alert showWaiting:self title:@"Waiting..." subTitle:@"Blah de blah de blah, blah. Blah de blah de" closeButtonTitle:nil duration:5.0f];
107+
```
108+
109+
101110
###SCLAlertView properties
102111
```Objective-C
103112
//Dismiss on tap outside (Default is NO)
@@ -134,6 +143,7 @@ typedef NS_ENUM(NSInteger, SCLAlertViewStyle)
134143
Warning,
135144
Info,
136145
Edit,
146+
Waiting,
137147
Custom
138148
};
139149
```

SCLAlertView/SCLAlertView.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef NS_ENUM(NSInteger, SCLAlertViewStyle)
2626
Warning,
2727
Info,
2828
Edit,
29+
Waiting,
2930
Custom
3031
};
3132

@@ -77,6 +78,12 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground)
7778
*/
7879
@property UITextView *viewText;
7980

81+
/** Activity Indicator
82+
*
83+
* Holds the activityIndicator.
84+
*/
85+
@property UIActivityIndicatorView *activityIndicatorView;
86+
8087
/** Dismiss on tap outside
8188
*
8289
* A boolean value that determines whether to dismiss when tapping outside the SCLAlertView.
@@ -254,5 +261,15 @@ typedef NS_ENUM(NSInteger, SCLAlertViewBackground)
254261
*/
255262
- (void)showCustom:(UIViewController *)vc image:(UIImage *)image color:(UIColor *)color title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration;
256263

264+
/** Show Waiting SCLAlertView with UIActityIndicator.
265+
*
266+
* @param vc The view controller the alert view will be displayed in.
267+
* @param title The text displayed on the button.
268+
* @param subTitle The subtitle text of the alert view.
269+
* @param closeButtonTitle The text for the close button.
270+
* @param duration The amount of time the alert will remain on screen until it is automatically dismissed. If automatic dismissal is not desired, set to 0.
271+
*/
272+
- (void)showWaiting:(UIViewController *)vc title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration;
273+
257274

258275
@end

SCLAlertView/SCLAlertView.m

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ @implementation SCLAlertView
5151
CGFloat kCircleBackgroundTopPosition;
5252
CGFloat kCircleHeightBackground;
5353
CGFloat kCircleIconHeight;
54+
CGFloat kActivityIndicatorHeight;
5455
CGFloat kWindowWidth;
5556
CGFloat kWindowHeight;
5657
CGFloat kTextHeight;
@@ -85,6 +86,7 @@ - (instancetype)init
8586
kCircleBackgroundTopPosition = -15.0f;
8687
kCircleHeightBackground = 62.0f;
8788
kCircleIconHeight = 20.0f;
89+
kActivityIndicatorHeight = 40.0f;
8890
kWindowWidth = 240.0f;
8991
kWindowHeight = 178.0f;
9092
kSubTitleHeight = 90.0f;
@@ -95,7 +97,7 @@ - (instancetype)init
9597
_hideAnimationType = FadeOut;
9698
_showAnimationType = SlideInFromTop;
9799
_backgroundType = Shadow;
98-
100+
99101
// Init
100102
_labelTitle = [[UILabel alloc] init];
101103
_viewText = [[UITextView alloc] init];
@@ -106,13 +108,15 @@ - (instancetype)init
106108
_backgroundView = [[UIImageView alloc]initWithFrame:[self mainScreenFrame]];
107109
_buttons = [[NSMutableArray alloc] init];
108110
_inputs = [[NSMutableArray alloc] init];
111+
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
109112

110113
// Add Subviews
111114
[self.view addSubview:_contentView];
112115
[self.view addSubview:_circleViewBackground];
113116
[self.view addSubview:_circleView];
114117

115118
[_circleView addSubview:_circleIconImageView];
119+
[_circleView addSubview:_activityIndicatorView];
116120
[_contentView addSubview:_labelTitle];
117121
[_contentView addSubview:_viewText];
118122

@@ -217,6 +221,8 @@ -(void)viewWillLayoutSubviews
217221
_circleView.frame = CGRectMake(kWindowWidth / 2 - kCircleHeight / 2, kCircleTopPosition, kCircleHeight, kCircleHeight);
218222
_circleView.layer.cornerRadius = self.circleView.frame.size.height / 2;
219223
_circleIconImageView.frame = CGRectMake(kCircleHeight / 2 - kCircleIconHeight / 2, kCircleHeight / 2 - kCircleIconHeight / 2, kCircleIconHeight, kCircleIconHeight);
224+
_activityIndicatorView.frame =CGRectMake(kCircleHeight / 2 - kActivityIndicatorHeight / 2, kCircleHeight / 2 - kActivityIndicatorHeight / 2, kActivityIndicatorHeight, kActivityIndicatorHeight);
225+
220226
_labelTitle.frame = CGRectMake(12.0f, kCircleHeight / 2 + 12.0f, kWindowWidth - 24.0f, 40.0f);
221227
_viewText.frame = CGRectMake(12.0f, 74.0f, kWindowWidth - 24.0f, kTextHeight);
222228

@@ -515,6 +521,10 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag
515521
iconImage = SCLAlertViewStyleKit.imageOfEdit;
516522
break;
517523

524+
case Waiting:
525+
viewColor = UIColorFromRGB(0x6c125d);
526+
break;
527+
518528
case Custom:
519529
viewColor = color;
520530
iconImage = image;
@@ -596,7 +606,13 @@ -(SCLAlertViewResponder *)showTitle:(UIViewController *)vc image:(UIImage *)imag
596606

597607
// Alert view colour and images
598608
self.circleView.backgroundColor = viewColor;
599-
self.circleIconImageView.image = iconImage;
609+
610+
if (style == Waiting) {
611+
[self.activityIndicatorView startAnimating];
612+
} else {
613+
self.circleIconImageView.image = iconImage;
614+
}
615+
600616

601617
for (UITextField *textField in _inputs)
602618
{
@@ -681,6 +697,11 @@ - (void)showCustom:(UIViewController *)vc image:(UIImage *)image color:(UIColor
681697
[self showTitle:vc image:image color:color title:title subTitle:subTitle duration:duration completeText:closeButtonTitle style:Custom];
682698
}
683699

700+
- (void)showWaiting:(UIViewController *)vc title:(NSString *)title subTitle:(NSString *)subTitle closeButtonTitle:(NSString *)closeButtonTitle duration:(NSTimeInterval)duration
701+
{
702+
[self showTitle:vc image:nil color:nil title:title subTitle:subTitle duration:duration completeText:closeButtonTitle style:Waiting];
703+
}
704+
684705
#pragma mark - Visibility
685706

686707
- (BOOL)isVisible
@@ -790,6 +811,9 @@ - (void)hideView
790811
[self slideOutToRight];
791812
break;
792813
}
814+
815+
[_activityIndicatorView stopAnimating];
816+
793817
if (self.dismissBlock)
794818
{
795819
self.dismissBlock();

SCLAlertViewExample/Base.lproj/Storyboard.storyboard

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Ohq-jH-G4R">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="Ohq-jH-G4R">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
66
</dependencies>
77
<scenes>
88
<!--View Controller-->
@@ -116,12 +116,26 @@
116116
<action selector="showValidation:" destination="Ohq-jH-G4R" eventType="touchUpInside" id="1DV-xd-ugz"/>
117117
</connections>
118118
</button>
119+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fs5-sr-WWC">
120+
<rect key="frame" x="203" y="416" width="196" height="30"/>
121+
<constraints>
122+
<constraint firstAttribute="width" constant="196" id="hiy-05-eK2"/>
123+
</constraints>
124+
<state key="normal" title="Show Waiting">
125+
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
126+
</state>
127+
<connections>
128+
<action selector="showWaiting:" destination="Ohq-jH-G4R" eventType="touchUpInside" id="ler-Oz-x3u"/>
129+
</connections>
130+
</button>
119131
</subviews>
120132
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
121133
<constraints>
122134
<constraint firstItem="XBG-LD-1eZ" firstAttribute="trailing" secondItem="DRS-IB-vIQ" secondAttribute="trailing" constant="1" id="1Y3-zK-h2R"/>
123135
<constraint firstItem="4U1-31-wBg" firstAttribute="top" secondItem="7sB-cQ-cdn" secondAttribute="bottom" constant="8" symbolic="YES" id="30i-yc-AP5"/>
136+
<constraint firstItem="fs5-sr-WWC" firstAttribute="top" secondItem="XBG-LD-1eZ" secondAttribute="bottom" constant="8" symbolic="YES" id="3pL-9w-8Hf"/>
124137
<constraint firstItem="w0L-ki-asc" firstAttribute="top" secondItem="8ID-0w-GrU" secondAttribute="bottom" constant="8" symbolic="YES" id="5TC-fc-NE7"/>
138+
<constraint firstItem="fs5-sr-WWC" firstAttribute="centerX" secondItem="c2J-Bd-hKP" secondAttribute="centerX" id="8Ri-cB-lwW"/>
125139
<constraint firstItem="7sB-cQ-cdn" firstAttribute="centerX" secondItem="zXb-fx-bXk" secondAttribute="centerX" constant="-1" id="BPg-qW-WxA"/>
126140
<constraint firstItem="QYK-Po-EUn" firstAttribute="top" secondItem="4U1-31-wBg" secondAttribute="bottom" constant="8" symbolic="YES" id="Cm3-q7-Uqz"/>
127141
<constraint firstItem="DRS-IB-vIQ" firstAttribute="leading" secondItem="XBG-LD-1eZ" secondAttribute="leading" constant="-1" id="CzL-it-lGU"/>
@@ -145,7 +159,7 @@
145159
</viewController>
146160
<placeholder placeholderIdentifier="IBFirstResponder" id="Vz4-cZ-r73" userLabel="First Responder" sceneMemberID="firstResponder"/>
147161
</objects>
148-
<point key="canvasLocation" x="500.625" y="143.66197183098592"/>
162+
<point key="canvasLocation" x="500" y="143"/>
149163
</scene>
150164
</scenes>
151165
</document>

SCLAlertViewExample/ViewController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- (IBAction)showEdit:(id)sender;
1919
- (IBAction)showCustom:(id)sender;
2020
- (IBAction)showValidation:(id)sender;
21+
- (IBAction)showWaiting:(id)sender;
2122

2223
@end
2324

SCLAlertViewExample/ViewController.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ - (IBAction)showValidation:(id)sender
225225
[alert showEdit:self title:@"Validation" subTitle:@"Ensure the data is correct before dismissing!" closeButtonTitle:@"Cancel" duration:0];
226226
}
227227

228+
- (IBAction)showWaiting:(id)sender {
229+
SCLAlertView *alert = [[SCLAlertView alloc] init];
230+
231+
[alert showWaiting:self title:@"Waiting..."
232+
subTitle:@"Blah de blah de blah, blah. Blah de blah de"
233+
closeButtonTitle:nil duration:5.0f];
234+
}
235+
228236
- (void)firstButton
229237
{
230238
NSLog(@"First button tapped");

ScreenShots/ScreenShot5.png

38.1 KB
Loading

0 commit comments

Comments
 (0)