Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Beautiful animated Alert View. Written in Objective-C

License

NotificationsYou must be signed in to change notification settings

dogo/SCLAlertView

Repository files navigation

Animated Alert View written in Swift but ported to Objective-C, which can be used as aUIAlertView orUIAlertController replacement.

Build StatusCocoapodsPod LicenseCarthage compatible

BackgroundImage_BackgroundImageBackgroundImage_BackgroundImageBackgroundImage_BackgroundImageBackgroundImage

Fluent style

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);

Complex

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];

Easy to use

// 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 in a new window. (No UIViewController)

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];

Add buttons

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];

Add button timer

//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];

Add Text Attributes

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];

Add a text field

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];

Indeterminate progress

SCLAlertView *alert = [[SCLAlertViewalloc]init];    [alertshowWaiting:selftitle:@"Waiting..."subTitle:@"Blah de blah de blah, blah. Blah de blah de"closeButtonTitle:nilduration:5.0f];

Add a switch button

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];

Add custom view

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];

SCLAlertView properties

//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]]];

Helpers

//Receiving information that SCLAlertView is dismissed[alertalertIsDismissed:^{NSLog(@"SCLAlertView dismissed!");}];

Alert View Styles

typedefNS_ENUM(NSInteger, SCLAlertViewStyle){    SCLAlertViewStyleSuccess,    SCLAlertViewStyleError,    SCLAlertViewStyleNotice,    SCLAlertViewStyleWarning,    SCLAlertViewStyleInfo,    SCLAlertViewStyleEdit,    SCLAlertViewStyleWaiting,    SCLAlertViewStyleQuestion,    SCLAlertViewStyleCustom};

Alert View hide animation styles

typedefNS_ENUM(NSInteger, SCLAlertViewHideAnimation){    SCLAlertViewHideAnimationFadeOut,    SCLAlertViewHideAnimationSlideOutToBottom,    SCLAlertViewHideAnimationSlideOutToTop,    SCLAlertViewHideAnimationSlideOutToLeft,    SCLAlertViewHideAnimationSlideOutToRight,    SCLAlertViewHideAnimationSlideOutToCenter,    SCLAlertViewHideAnimationSlideOutFromCenter,    SCLAlertViewHideAnimationSimplyDisappear};

Alert View show animation styles

typedefNS_ENUM(NSInteger, SCLAlertViewShowAnimation){    SCLAlertViewShowAnimationFadeIn,    SCLAlertViewShowAnimationSlideInFromBottom,    SCLAlertViewShowAnimationSlideInFromTop,    SCLAlertViewShowAnimationSlideInFromLeft,    SCLAlertViewShowAnimationSlideInFromRight,    SCLAlertViewShowAnimationSlideInFromCenter,    SCLAlertViewShowAnimationSlideInToCenter,    SCLAlertViewShowAnimationSimplyAppear};

Alert View background styles

typedefNS_ENUM(NSInteger, SCLAlertViewBackground){    SCLAlertViewBackgroundShadow,    SCLAlertViewBackgroundBlur,    SCLAlertViewBackgroundTransparent};

Installation

SCLAlertView-Objective-C is available through :

To install add the following line to your Podfile:

pod 'SCLAlertView-Objective-C'
github "dogo/SCLAlertView"

Collaboration

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.

Incoming improvements

  • More animations
  • Performance tests
  • Remove some hardcode values

Plugin integrations

Thanks to the original team

https://github.com/vikmeup/SCLAlertView-Swift


[8]ページ先頭

©2009-2025 Movatter.jp