- Notifications
You must be signed in to change notification settings - Fork532
Beautiful animated Alert View. Written in Objective-C
License
NotificationsYou must be signed in to change notification settings
dogo/SCLAlertView
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Animated Alert View written in Swift but ported to Objective-C, which can be used as aUIAlertView
orUIAlertController
replacement.
SCLAlertViewBuilder *builder = [SCLAlertViewBuildernew].addButtonWithActionBlock(@"Send", ^{/*work here*/ });SCLAlertViewShowBuilder *showBuilder = [SCLAlertViewShowBuildernew].style(SCLAlertViewStyleWarning).title(@"Title").subTitle(@"Subtitle").duration(0);[showBuildershowAlertView:builder.alertViewonViewController:self.window.rootViewController];// or evenshowBuilder.show(builder.alertView, self.window.rootViewController);
NSString *title =@"Title";NSString *message =@"Message";NSString *cancel =@"Cancel";NSString *done =@"Done"; SCLALertViewTextFieldBuilder *textField = [SCLALertViewTextFieldBuildernew].title(@"Code"); SCLALertViewButtonBuilder *doneButton = [SCLALertViewButtonBuildernew].title(done) .validationBlock(^BOOL{NSString *code = [textField.textField.textcopy];return [codeisVisible]; }) .actionBlock(^{NSString *code = [textField.textField.textcopy]; [selfconfirmPhoneNumberWithCode:code]; }); SCLAlertViewBuilder *builder = [SCLAlertViewBuildernew] .showAnimationType(SCLAlertViewShowAnimationFadeIn) .hideAnimationType(SCLAlertViewHideAnimationFadeOut) .shouldDismissOnTapOutside(NO) .addTextFieldWithBuilder(textField) .addButtonWithBuilder(doneButton); SCLAlertViewShowBuilder *showBuilder = [SCLAlertViewShowBuildernew] .style(SCLAlertViewStyleCustom) .image([SCLAlertViewStyleKitimageOfInfo]) .color([UIColorblueColor]) .title(title) .subTitle(message) .closeButtonTitle(cancel) .duration(0.0f); [showBuildershowAlertView:builder.alertViewonViewController:self];
// Get startedSCLAlertView *alert = [[SCLAlertViewalloc]init];[alertshowSuccess:selftitle:@"Hello World"subTitle:@"This is a more descriptive text."closeButtonTitle:@"Done"duration:0.0f];// Alternative alert types[alertshowError:selftitle:@"Hello Error"subTitle:@"This is a more descriptive error text."closeButtonTitle:@"OK"duration:0.0f];// Error[alertshowNotice:selftitle:@"Hello Notice"subTitle:@"This is a more descriptive notice text."closeButtonTitle:@"Done"duration:0.0f];// Notice[alertshowWarning:selftitle:@"Hello Warning"subTitle:@"This is a more descriptive warning text."closeButtonTitle:@"Done"duration:0.0f];// Warning[alertshowInfo:selftitle:@"Hello Info"subTitle:@"This is a more descriptive info text."closeButtonTitle:@"Done"duration:0.0f];// Info[alertshowEdit:selftitle:@"Hello Edit"subTitle:@"This is a more descriptive info text with a edit textbox"closeButtonTitle:@"Done"duration:0.0f];// Edit[alertshowCustom:selfimage:[UIImageimageNamed:@"git"]color:colortitle:@"Custom"subTitle:@"Add a custom icon and color for your own type of alert!"closeButtonTitle:@"OK"duration:0.0f];// Custom[alertshowWaiting:selftitle:@"Waiting..."subTitle:@"Blah de blah de blah, blah. Blah de blah de"closeButtonTitle:nilduration:5.0f];[alertshowQuestion:selftitle:@"Question?"subTitle:kSubtitlecloseButtonTitle:@"Dismiss"duration:0.0f];// Using custom alert widthSCLAlertView *alert = [[SCLAlertViewalloc]initWithWindowWidth:300.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]initWithNewWindow];[alertshowSuccess:@"Hello World"subTitle:@"This is a more descriptive text."closeButtonTitle:@"Done"duration:0.0f];// Alternative alert types[alertshowError:@"Hello Error"subTitle:@"This is a more descriptive error text."closeButtonTitle:@"OK"duration:0.0f];// Error[alertshowNotice:@"Hello Notice"subTitle:@"This is a more descriptive notice text."closeButtonTitle:@"Done"duration:0.0f];// Notice[alertshowWarning:@"Hello Warning"subTitle:@"This is a more descriptive warning text."closeButtonTitle:@"Done"duration:0.0f];// Warning[alertshowInfo:@"Hello Info"subTitle:@"This is a more descriptive info text."closeButtonTitle:@"Done"duration:0.0f];// Info[alertshowEdit:@"Hello Edit"subTitle:@"This is a more descriptive info text with a edit textbox"closeButtonTitle:@"Done"duration:0.0f];// Edit[alertshowCustom:[UIImageimageNamed:@"git"]color:colortitle:@"Custom"subTitle:@"Add a custom icon and color for your own type of alert!"closeButtonTitle:@"OK"duration:0.0f];// Custom[alertshowWaiting:@"Waiting..."subTitle:@"Blah de blah de blah, blah. Blah de blah de"closeButtonTitle:nilduration:5.0f];[alertshowQuestion:@"Question?"subTitle:kSubtitlecloseButtonTitle:@"Dismiss"duration:0.0f];// Using custom alert widthSCLAlertView *alert = [[SCLAlertViewalloc]initWithNewWindowWidth:300.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init];//Using Selector[alertaddButton:@"First Button"target:selfselector:@selector(firstButton)];//Using Block[alertaddButton:@"Second Button"actionBlock:^(void) {NSLog(@"Second button tapped");}];//Using Blocks With Validation[alertaddButton:@"Validate"validationBlock:^BOOL {BOOL passedValidation = ....return passedValidation;}actionBlock:^{// handle successful validation here}];[alertshowSuccess:selftitle:@"Button View"subTitle:@"This alert view has buttons"closeButtonTitle:@"Done"duration:0.0f];
//The index of the button to add the timer display to.[alertaddTimerToButtonIndex:0reverse:NO];
Example:
SCLAlertView *alert = [[SCLAlertViewalloc]init];[alertaddTimerToButtonIndex:0reverse:YES];[alertshowInfo:selftitle:@"Countdown Timer"subTitle:@"This alert has a duration set, and a countdown timer on the Dismiss button to show how long is left."closeButtonTitle:@"Dismiss"duration:10.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init];alert.attributedFormatBlock = ^NSAttributedString* (NSString *value){NSMutableAttributedString *subTitle = [[NSMutableAttributedStringalloc]initWithString:value];NSRange redRange = [valuerangeOfString:@"Attributed"options:NSCaseInsensitiveSearch]; [subTitleaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor]range:redRange];NSRange greenRange = [valuerangeOfString:@"successfully"options:NSCaseInsensitiveSearch]; [subTitleaddAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor]range:greenRange];NSRangeunderline = [valuerangeOfString:@"completed"options:NSCaseInsensitiveSearch]; [subTitleaddAttributes:@{NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)}range:underline];return subTitle;};[alertshowSuccess:selftitle:@"Button View"subTitle:@"Attributed string operation successfully completed."closeButtonTitle:@"Done"duration:0.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init];UITextField *textField = [alertaddTextField:@"Enter your name"setDefaultText:nil];[alertaddButton:@"Show Name"actionBlock:^(void) {NSLog(@"Text value:%@", textField.text);}];[alertshowEdit:selftitle:@"Edit View"subTitle:@"This alert view shows a text box"closeButtonTitle:@"Done"duration:0.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init]; [alertshowWaiting:selftitle:@"Waiting..."subTitle:@"Blah de blah de blah, blah. Blah de blah de"closeButtonTitle:nilduration:5.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init]; SCLSwitchView *switchView = [alertaddSwitchViewWithLabel:@"Don't show again".uppercaseString];switchView.tintColor = [UIColorbrownColor]; [alertaddButton:@"Done"actionBlock:^(void) {NSLog(@"Show again?%@", switchView.isSelected ?@"-No":@"-Yes");}]; [alertshowCustom:selfimage:[UIImageimageNamed:@"switch"]color:[UIColorbrownColor]title:kInfoTitlesubTitle:kSubtitlecloseButtonTitle:nilduration:0.0f];
SCLAlertView *alert = [[SCLAlertViewalloc]init];UIView *customView = [[UIViewalloc]initWithFrame:CGRectMake(0.0f,0.0f,215.0f,80.0f)];customView.backgroundColor = [UIColorredColor];[alertaddCustomView:customView];[alertshowNotice:selftitle:@"Title"subTitle:@"This alert view shows a custom view"closeButtonTitle:@"Done"duration:0.0f];
//Dismiss on tap outside (Default is NO)alert.shouldDismissOnTapOutside =YES;//Hide animation type (Default is SCLAlertViewHideAnimationFadeOut)alert.hideAnimationType = SCLAlertViewHideAnimationSlideOutToBottom;//Show animation type (Default is SCLAlertViewShowAnimationSlideInFromTop)alert.showAnimationType = SCLAlertViewShowAnimationSlideInFromLeft;//Set background type (Default is SCLAlertViewBackgroundShadow)alert.backgroundType = SCLAlertViewBackgroundBlur;//Overwrite SCLAlertView (Buttons, top circle and borders) colorsalert.customViewColor = [UIColorpurpleColor];//Set custom tint color for icon image.alert.iconTintColor = [UIColorpurpleColor];//Override top circle tint color with background coloralert.tintTopCircle =NO;//Set custom corner radius for SCLAlertViewalert.cornerRadius =13.0f;//Overwrite SCLAlertView background coloralert.backgroundViewColor = [UIColorcyanColor];//Returns if the alert is visible or not.alert.isVisible;//Make the top circle icon largeralert.useLargerIcon =YES;//Using soundalert.soundURL = [NSURLfileURLWithPath:[NSStringstringWithFormat:@"%@/right_answer.mp3", [[NSBundlemainBundle]resourcePath]]];
//Receiving information that SCLAlertView is dismissed[alertalertIsDismissed:^{NSLog(@"SCLAlertView dismissed!");}];
typedefNS_ENUM(NSInteger, SCLAlertViewStyle){ SCLAlertViewStyleSuccess, SCLAlertViewStyleError, SCLAlertViewStyleNotice, SCLAlertViewStyleWarning, SCLAlertViewStyleInfo, SCLAlertViewStyleEdit, SCLAlertViewStyleWaiting, SCLAlertViewStyleQuestion, SCLAlertViewStyleCustom};
typedefNS_ENUM(NSInteger, SCLAlertViewHideAnimation){ SCLAlertViewHideAnimationFadeOut, SCLAlertViewHideAnimationSlideOutToBottom, SCLAlertViewHideAnimationSlideOutToTop, SCLAlertViewHideAnimationSlideOutToLeft, SCLAlertViewHideAnimationSlideOutToRight, SCLAlertViewHideAnimationSlideOutToCenter, SCLAlertViewHideAnimationSlideOutFromCenter, SCLAlertViewHideAnimationSimplyDisappear};
typedefNS_ENUM(NSInteger, SCLAlertViewShowAnimation){ SCLAlertViewShowAnimationFadeIn, SCLAlertViewShowAnimationSlideInFromBottom, SCLAlertViewShowAnimationSlideInFromTop, SCLAlertViewShowAnimationSlideInFromLeft, SCLAlertViewShowAnimationSlideInFromRight, SCLAlertViewShowAnimationSlideInFromCenter, SCLAlertViewShowAnimationSlideInToCenter, SCLAlertViewShowAnimationSimplyAppear};
typedefNS_ENUM(NSInteger, SCLAlertViewBackground){ SCLAlertViewBackgroundShadow, SCLAlertViewBackgroundBlur, SCLAlertViewBackgroundTransparent};
SCLAlertView-Objective-C is available through :
To install add the following line to your Podfile:
pod 'SCLAlertView-Objective-C'
github "dogo/SCLAlertView"
I tried to build an easy to use API, while beeing flexible enough for multiple variations, but I'm sure there are ways of improving and adding more features, so feel free to collaborate with ideas, issues and/or pull requests.
- More animations
- Performance tests
- Remove some hardcode values
- nativescript-fancyalert for NativeScript
- Use SCLAlertView withNativeScript
- Design@SherzodMx Sherzod Max
- Development@hackua Viktor Radchenko
- Improvements by@bih Bilawal Hameed,@rizjoj Riz Joj
About
Beautiful animated Alert View. Written in Objective-C