123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454 |
- //
- // LCActionSheet.h
- // LCActionSheet
- //
- // Created by Leo on 2015/4/27.
- //
- // Copyright (c) 2015-2017 Leo <leodaxia@gmail.com>
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in all
- // copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- // SOFTWARE.
- #import <UIKit/UIKit.h>
- #import "LCActionSheetConfig.h"
- @class LCActionSheet;
- NS_ASSUME_NONNULL_BEGIN
- #pragma mark - LCActionSheet Block
- /**
- Handle click button.
- */
- typedef void(^LCActionSheetClickedHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
- /**
- Handle action sheet will present.
- */
- typedef void(^LCActionSheetWillPresentHandler)(LCActionSheet *actionSheet);
- /**
- Handle action sheet did present.
- */
- typedef void(^LCActionSheetDidPresentHandler)(LCActionSheet *actionSheet);
- /**
- Handle action sheet will dismiss.
- */
- typedef void(^LCActionSheetWillDismissHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
- /**
- Handle action sheet did dismiss.
- */
- typedef void(^LCActionSheetDidDismissHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
- #pragma mark - LCActionSheet Delegate
- @protocol LCActionSheetDelegate <NSObject>
- @optional
- /**
- Handle click button.
- */
- - (void)actionSheet:(LCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
- /**
- Handle action sheet will present.
- */
- - (void)willPresentActionSheet:(LCActionSheet *)actionSheet;
- /**
- Handle action sheet did present.
- */
- - (void)didPresentActionSheet:(LCActionSheet *)actionSheet;
- /**
- Handle action sheet will dismiss.
- */
- - (void)actionSheet:(LCActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
- /**
- Handle action sheet did dismiss.
- */
- - (void)actionSheet:(LCActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
- @end
- #pragma mark - LCActionSheet
- @interface LCActionSheet : UIView
- #pragma mark - Properties
- /**
- Title.
- */
- @property (nullable, nonatomic, copy) NSString *title;
- /**
- Cancel button's title.
- */
- @property (nullable, nonatomic, copy) NSString *cancelButtonTitle;
- /**
- Cancel button's index.
- */
- @property (nonatomic, assign, readonly) NSInteger cancelButtonIndex;
- /**
- LCActionSheet's delegate.
- */
- @property (nullable, nonatomic, weak) id<LCActionSheetDelegate> delegate;
- /**
- Deprecated, use `destructiveButtonIndexSet` instead.
- */
- @property (nullable, nonatomic, strong) NSIndexSet *redButtonIndexSet __deprecated_msg("Property deprecated. Use `destructiveButtonIndexSet` instead.");
- /**
- All destructive buttons' set. You should give it the `NSNumber` type items.
- */
- @property (nullable, nonatomic, strong) NSIndexSet *destructiveButtonIndexSet;
- /**
- Destructive button's color. Default is RGB(254, 67, 37).
- */
- @property (nonatomic, strong) UIColor *destructiveButtonColor;
- /**
- Title's color. Default is `[UIColor blackColor]`.
- */
- @property (nonatomic, strong) UIColor *titleColor;
- /**
- Buttons' color, without destructive buttons. Default is `[UIColor blackColor]`.
- */
- @property (nonatomic, strong) UIColor *buttonColor;
- /**
- Title's font. Default is `[UIFont systemFontOfSize:14.0f]`.
- */
- @property (nonatomic, strong) UIFont *titleFont;
- /**
- All buttons' font. Default is `[UIFont systemFontOfSize:18.0f]`.
- */
- @property (nonatomic, strong) UIFont *buttonFont;
- /**
- All buttons' height. Default is 49.0f;
- */
- @property (nonatomic, assign) CGFloat buttonHeight;
- /**
- If buttons' bottom view can scrolling. Default is NO.
- */
- @property (nonatomic, assign, getter=canScrolling) BOOL scrolling;
- /**
- Visible buttons' count. You have to set `scrolling = YES` if you want to set it.
- */
- @property (nonatomic, assign) CGFloat visibleButtonCount;
- /**
- Animation duration. Default is 0.3 seconds.
- */
- @property (nonatomic, assign) CGFloat animationDuration;
- /**
- Opacity of dark background. Default is 0.3f.
- */
- @property (nonatomic, assign) CGFloat darkOpacity;
- /**
- If you can tap darkView to dismiss. Defalut is NO, you can tap dardView to dismiss.
- */
- @property (nonatomic, assign) BOOL darkViewNoTaped;
- /**
- Clear blur effect. Default is NO, don't clear blur effect.
- */
- @property (nonatomic, assign) BOOL unBlur;
- /**
- Style of blur effect. Default is `UIBlurEffectStyleExtraLight`. iOS 8.0 +
- */
- @property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle;
- /**
- Title's edge insets. Default is `UIEdgeInsetsMake(15.0f, 15.0f, 15.0f, 15.0f)`.
- */
- @property (nonatomic, assign) UIEdgeInsets titleEdgeInsets;
- /**
- Cell's separator color. Default is `RGBA(170/255.0f, 170/255.0f, 170/255.0f, 0.5f)`.
- */
- @property (nonatomic, strong) UIColor *separatorColor;
- /**
- Auto hide when the device rotated. Default is NO, won't auto hide.
- */
- @property (nonatomic, assign) BOOL autoHideWhenDeviceRotated;
- /**
- LCActionSheet clicked handler.
- */
- @property (nullable, nonatomic, copy) LCActionSheetClickedHandler clickedHandler;
- /**
- LCActionSheet will present handler.
- */
- @property (nullable, nonatomic, copy) LCActionSheetWillPresentHandler willPresentHandler;
- /**
- LCActionSheet did present handler.
- */
- @property (nullable, nonatomic, copy) LCActionSheetDidPresentHandler didPresentHandler;
- /**
- LCActionSheet will dismiss handler.
- */
- @property (nullable, nonatomic, copy) LCActionSheetWillDismissHandler willDismissHandler;
- /**
- LCActionSheet did dismiss handler.
- */
- @property (nullable, nonatomic, copy) LCActionSheetDidDismissHandler didDismissHandler;
- #pragma mark - Methods
- #pragma mark Delegate
- /**
- Initialize an instance of LCActionSheet (Delegate).
- @param title title
- @param delegate delegate
- @param cancelButtonTitle cancelButtonTitle
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- delegate:(nullable id<LCActionSheetDelegate>)delegate
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Delegate).
- @param title title
- @param delegate delegate
- @param cancelButtonTitle cancelButtonTitle
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- delegate:(nullable id<LCActionSheetDelegate>)delegate
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- /**
- Initialize an instance of LCActionSheet (Delegate).
- @param title title
- @param delegate delegate
- @param cancelButtonTitle cancelButtonTitle
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- delegate:(nullable id<LCActionSheetDelegate>)delegate
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Delegate).
- @param title title
- @param delegate delegate
- @param cancelButtonTitle cancelButtonTitle
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- delegate:(nullable id<LCActionSheetDelegate>)delegate
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- #pragma mark Block
- /**
- Initialize an instance of LCActionSheet (Block).
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param clickedHandler clickedHandler
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- clicked:(nullable LCActionSheetClickedHandler)clickedHandler
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Block).
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param clickedHandler clickedHandler
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- clicked:(nullable LCActionSheetClickedHandler)clickedHandler
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- /**
- Initialize an instance of LCActionSheet (Block).
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param clickedHandler clickedHandler
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- clicked:(nullable LCActionSheetClickedHandler)clickedHandler
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Block).
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param clickedHandler clickedHandler
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- clicked:(nullable LCActionSheetClickedHandler)clickedHandler
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- /**
- Initialize an instance of LCActionSheet (Block).
-
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param didDismissHandler didDismissHandler
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Block).
-
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param didDismissHandler didDismissHandler
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- + (instancetype)sheetWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- /**
- Initialize an instance of LCActionSheet (Block).
-
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param didDismissHandler didDismissHandler
- @param otherButtonTitles otherButtonTitles
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
- otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Initialize an instance of LCActionSheet with title array (Block).
-
- @param title title
- @param cancelButtonTitle cancelButtonTitle
- @param didDismissHandler didDismissHandler
- @param otherButtonTitleArray otherButtonTitleArray
-
- @return An instance of LCActionSheet.
- */
- - (instancetype)initWithTitle:(nullable NSString *)title
- cancelButtonTitle:(nullable NSString *)cancelButtonTitle
- didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
- otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
- #pragma mark Append & Show
- /**
- Append buttons with titles.
- @param titles titles
- */
- - (void)appendButtonsWithTitles:(nullable NSString *)titles, ... NS_REQUIRES_NIL_TERMINATION;
- /**
- Append button at index with title.
- @param title title
- @param index index
- */
- - (void)appendButtonWithTitle:(nullable NSString *)title atIndex:(NSInteger)index;
- /**
- Append buttons at indexSet with titles.
- @param titles titles
- @param indexes indexes
- */
- - (void)appendButtonsWithTitles:(NSArray<NSString *> *)titles atIndexes:(NSIndexSet *)indexes;
- /**
- Show the instance of LCActionSheet.
- */
- - (void)show;
- @end
- NS_ASSUME_NONNULL_END
|