Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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
Appearance settings

Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one. You can customize every detail. Make AlertView of your dream! :)

License

NotificationsYou must be signed in to change notification settings

Friend-LGA/LGAlertView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one.You can customize every detail. Make AlertView of your dream! :)

PlatformCocoaPodsCarthageLicense

Preview

Default Alert View

Default Action Sheet

Blurred Alert View

Blurred Action Sheet

Custom Alert View

Custom Action Sheet

Screenshots above are just few examples that you can achieve, you are free to create any other style

Installation

LGAlertView versioniOS version
<= 2.0.13>= 6.0
>= 2.1.0>= 8.0

With source code

Download repository, then addLGAlertView directory to your project.

Then import header files where you need to use the library

Objective-C
#import"LGAlertView.h"
Swift

For swift you need to createbridging header

// BridgingHeader.h#import"LGAlertView.h"

With CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. To install with cocoaPods, follow the "Get Started" section onCocoaPods.

Podfile

platform:ios,'8.0'use_frameworks!pod'LGAlertView'

Then import framework where you need to use the library

Objective-C
#import<LGAlertView/LGAlertView.h>// OR@import LGAlertView;
Swift
import LGAlertView

With Carthage

Carthage is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods. To install with carthage, follow the instruction onCarthage.

Cartfile

github "Friend-LGA/LGAlertView"

Then import framework where you need to use the library

Objective-C
#import<LGAlertView/LGAlertView.h>// OR@import LGAlertView;
Swift
import LGAlertView

Usage

Initialization

You have several methods for initialization:

Objective-C
- (nonnullinstancetype)initWithTitle:(nullableNSString *)title                              message:(nullableNSString *)message                                style:(LGAlertViewStyle)style                         buttonTitles:(nullableNSArray<NSString *> *)buttonTitles                    cancelButtonTitle:(nullableNSString *)cancelButtonTitle               destructiveButtonTitle:(nullableNSString *)destructiveButtonTitle;- (nonnullinstancetype)initWithViewAndTitle:(nullableNSString *)title                                     message:(nullableNSString *)message                                       style:(LGAlertViewStyle)style                                        view:(nullable UIView *)view                                buttonTitles:(nullableNSArray<NSString *> *)buttonTitles                           cancelButtonTitle:(nullableNSString *)cancelButtonTitle                      destructiveButtonTitle:(nullableNSString *)destructiveButtonTitle;- (nonnullinstancetype)initWithActivityIndicatorAndTitle:(nullableNSString *)title                                                  message:(nullableNSString *)message                                                    style:(LGAlertViewStyle)style                                             buttonTitles:(nullableNSArray<NSString *> *)buttonTitles                                        cancelButtonTitle:(nullableNSString *)cancelButtonTitle                                   destructiveButtonTitle:(nullableNSString *)destructiveButtonTitle;- (nonnullinstancetype)initWithProgressViewAndTitle:(nullableNSString *)title                                             message:(nullableNSString *)message                                               style:(LGAlertViewStyle)style                                   progressLabelText:(nullableNSString *)progressLabelText                                        buttonTitles:(nullableNSArray<NSString *> *)buttonTitles                                   cancelButtonTitle:(nullableNSString *)cancelButtonTitle                              destructiveButtonTitle:(nullableNSString *)destructiveButtonTitle;- (nonnullinstancetype)initWithTextFieldsAndTitle:(nullableNSString *)title                                           message:(nullableNSString *)message                                numberOfTextFields:(NSUInteger)numberOfTextFields                            textFieldsSetupHandler:(LGAlertViewTextFieldsSetupHandler)textFieldsSetupHandler                                      buttonTitles:(nullableNSArray<NSString *> *)buttonTitles                                 cancelButtonTitle:(nullableNSString *)cancelButtonTitle                            destructiveButtonTitle:(nullableNSString *)destructiveButtonTitle;
Swift
publicinit(title:String?,          message:String?,            style:LGAlertViewStyle,     buttonTitles:[String]?,cancelButtonTitle:String?,destructiveButtonTitle:String?)publicinit(viewAndTitle title:String?,                       message:String?,                         style:LGAlertViewStyle,                          view:UIView?,                  buttonTitles:[String]?,             cancelButtonTitle:String?,        destructiveButtonTitle:String?)publicinit(activityIndicatorAndTitle title:String?,                                    message:String?,                                      style:LGAlertViewStyle,                               buttonTitles:[String]?,                          cancelButtonTitle:String?,                     destructiveButtonTitle:String?)publicinit(progressViewAndTitle title:String?,                               message:String?,                                 style:LGAlertViewStyle,                     progressLabelText:String?,                          buttonTitles:[String]?,                     cancelButtonTitle:String?,                destructiveButtonTitle:String?)publicinit(textFieldsAndTitle title:String?,                             message:String?,                  numberOfTextFields:UInt,              textFieldsSetupHandler:LGAlertView.LGAlertViewTextFieldsSetupHandler?,                        buttonTitles:[String]?,                   cancelButtonTitle:String?,              destructiveButtonTitle:String?)

More init methods you can find inLGAlertView.h

Setup

You can change properties only before you show alert view, after this to change something is impossible.

Appearance

Instead of change properties for every new alert view, you can useappearance to set them all only once andnew alert views will use it by default:

Objective-C
[LGAlertViewappearance].tintColor = UIColor.greenColor;[LGAlertViewappearance].cancelOnTouch =NO;[LGAlertViewappearance].dismissOnAction =NO;[LGAlertViewappearance]...[LGAlertViewappearance]...
Swift
LGAlertView.appearance().tintColor=.greenLGAlertView.appearance().cancelOnTouch=falseLGAlertView.appearance().dismissOnAction=falseLGAlertView.appearance()...LGAlertView.appearance()...

Action Sheet Safe Area

By defaultLGAlertView withLGAlertViewStyleActionSheet style doesn't use safe area insets.So for now it's up to you to set the offset, and it as easy as this:

Objective-C
if (@available(iOS11.0, *)) {    [LGAlertViewappearance].cancelButtonOffsetY = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets.bottom;}
Swift
if #available(iOS11.0,*){LGAlertView.appearance().cancelButtonOffsetY=UIApplication.sharedApplication.windows.firstObject.safeAreaInsets.bottom}

Buttons

If you want to set properties for each button individually, you can use method:

Objective-C
- (void)setButtonPropertiesAtIndex:(NSUInteger)index handler:(void(^ _Nonnull)(LGAlertViewButtonProperties * _Nonnull properties))handler;[alertViewsetButtonPropertiesAtIndex:0handler:^(LGAlertViewButtonProperties * _Nonnull properties) {    properties.titleColor = UIColor.yellowColor;    properties.image = [UIImageimageNamed:@"SuperImage"];// properties...// properties...}];
Swift
openfunc setButtonPropertiesAt(_ index:UInt, handler:@escaping(LGAlertViewButtonProperties)->Swift.Void)alertView.setButtonPropertiesAt(0){(properties: LGAlertViewButtonProperties) in    properties.titleColor=.yellow    properties.image=UIImage(named:"SuperImage")    // properties...    // properties...}

Enable / Disable

You can enable and disable buttons:

Objective-C
alertView.cancelButtonEnabled =YES;alertView.destructiveButtonEnabled =YES;[alertViewsetButtonEnabled:YESatIndex:0];
Swift
alertView.cancelButtonEnabled=truealertView.destructiveButtonEnabled=truealertView.setButtonEnabled(true, index:0)

Retain Cycle

When you use blocks and if you need to useself inside it, then you need to make weak reference toself to avoid retain cycle:

Objective-C
__weaktypeof(self) wself = self;alertView.cancelHandler = ^(LGAlertView *alertView) {    __strongtypeof(wself) sself = wself;    [sselfsomeMethod];};
Swift
alertView.cancelHandler={[unowned self](alertView:LGAlertView)inself.someMethod()}

Blur

You can use UIBlurEffect with next properties:

UIBlurEffect *coverBlurEffect;

For example:

Objective-C
alertView.coverBlurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleRegular];
Swift
alertView.coverBlurEffect=UIBlurEffect(style:.regular)

If you want to change color of blurred view, use:

UIColor *coverColor;

For example:

Objective-C
alertView.coverColor = [UIColorcolorWithRed:0.0green:0.5blue:1.0alpha:0.1];
Swift
alertView.coverColor=UIColor(red:0.0, green:0.5, blue:1.0, alpha:0.1)

If you want to change intensity of blurred view, use:

CGFloat coverAlpha;

For example:

alertView.coverAlpha =0.9;

Handle actions

To handle actions you can use blocks, delegate or notifications:

Delegate

Objective-C
<LGAlertViewDelegate>@optional- (void)alertViewWillShow:(nonnull LGAlertView *)alertView;- (void)alertViewDidShow:(nonnull LGAlertView *)alertView;- (void)alertViewWillDismiss:(nonnull LGAlertView *)alertView;- (void)alertViewDidDismiss:(nonnull LGAlertView *)alertView;- (void)alertView:(nonnull LGAlertView *)alertView clickedButtonAtIndex:(NSUInteger)index title:(nullableNSString *)title;- (void)alertViewCancelled:(nonnull LGAlertView *)alertView;- (void)alertViewDestructed:(nonnull LGAlertView *)alertView;- (void)alertView:(nonnull LGAlertView *)alertView didDismissAfterClickedButtonAtIndex:(NSUInteger)index title:(nullableNSString *)title;- (void)alertViewDidDismissAfterCancelled:(nonnull LGAlertView *)alertView;- (void)alertViewDidDismissAfterDestructed:(nonnull LGAlertView *)alertView;- (void)showAnimationsForAlertView:(nonnull LGAlertView *)alertView duration:(NSTimeInterval)duration;- (void)dismissAnimationsForAlertView:(nonnull LGAlertView *)alertView duration:(NSTimeInterval)duration;
Swift
<LGAlertViewDelegate>optionalpublicfunc alertViewWillShow(_ alertView:LGAlertView)optionalpublicfunc alertViewDidShow(_ alertView:LGAlertView)optionalpublicfunc alertViewWillDismiss(_ alertView:LGAlertView)optionalpublicfunc alertViewDidDismiss(_ alertView:LGAlertView)optionalpublicfunc alertView(_ alertView:LGAlertView, clickedButtonAtIndex index:UInt, title:String?)optional publicfunc alertViewCancelled(_ alertView:LGAlertView)optional publicfunc alertViewDestructed(_ alertView:LGAlertView)optional publicfunc alertView(_ alertView:LGAlertView, didDismissAfterClickedButtonAtIndex index:UInt, title:String?)optional publicfunc alertViewDidDismissAfterCancelled(_ alertView:LGAlertView)optional publicfunc alertViewDidDismissAfterDestructed(_ alertView:LGAlertView)optional publicfunc showAnimationsForAlertView(_ alertView:LGAlertView, duration:NSTimeInterval)optional publicfunc dismissAnimationsForAlertView(_ alertView:LGAlertView, duration:NSTimeInterval)

Blocks

Objective-C
void(^ _Nullable willShowHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable willShowHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable didShowHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable willDismissHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable didDismissHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable actionHandler)(LGAlertView * _Nonnull alertView,NSUInteger index,NSString * _Nullable title);void(^ _Nullable cancelHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable destructiveHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable didDismissAfterActionHandler)(LGAlertView * _Nonnull alertView,NSUInteger index,NSString * _Nullable title);void(^ _Nullable didDismissAfterCancelHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable didDismissAfterDestructiveHandler)(LGAlertView * _Nonnull alertView);void(^ _Nullable showAnimationsBlock)(LGAlertView * _Nonnull alertView,NSTimeInterval duration);void(^ _Nullable dismissAnimationsBlock)(LGAlertView * _Nonnull alertView,NSTimeInterval duration);
Swift
openvarwillShowHandler:((alertView:LGAlertView)->Swift.Void)?openvardidShowHandler:((alertView:LGAlertView)->Swift.Void)?openvarwillDismissHandler:((alertView:LGAlertView)->Swift.Void)?openvardidDismissHandler:((alertView:LGAlertView)->Swift.Void)?openvaractionHandler:((alertView:LGAlertView, index:NSUInteger, title:NSString)->Swift.Void)?openvarcancelHandler:((alertView:LGAlertView)->Swift.Void)?openvardestructiveHandler:((alertView:LGAlertView)->Swift.Void)?openvardidDismissAfterActionHandler:((alertView:LGAlertView, index:NSUInteger, title:NSString)->Swift.Void)?openvardidDismissAfterCancelHandler:((alertView:LGAlertView)->Swift.Void)?openvardidDismissAfterDestructiveHandler:((alertView:LGAlertView)->Swift.Void)?openvarshowAnimationsBlock:((alertView:LGAlertView, duration:NSTimeInterval)->Swift.Void)?openvardismissAnimationsBlock:((alertView:LGAlertView, duration:NSTimeInterval)->Swift.Void)?

Notifications

LGAlertViewWillShowNotificationLGAlertViewDidShowNotificationLGAlertViewWillDismissNotificationLGAlertViewDidDismissNotificationLGAlertViewActionNotificationLGAlertViewCancelNotificationLGAlertViewDestructiveNotificationLGAlertViewDidDismissAfterActionNotification;LGAlertViewDidDismissAfterCancelNotification;LGAlertViewDidDismissAfterDestructiveNotification;LGAlertViewShowAnimationsNotification;LGAlertViewDismissAnimationsNotification;

More

For more details try XcodeDemo project and seeLGAlertView.h

Frameworks

If you like LGAlertView, check out my other useful libraries:

  • LGSideMenuControlleriOS view controller, shows left and right views by pressing button or gesture.
  • LGPlusButtonsViewCustomizable iOS implementation of Floating Action Button (Google Plus Button, fab).

License

LGAlertView is released under the MIT license. SeeLICENSE for details.

About

Customizable implementation of UIAlertViewController, UIAlertView and UIActionSheet. All in one. You can customize every detail. Make AlertView of your dream! :)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp