LCActionSheet.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. //
  2. // LCActionSheet.h
  3. // LCActionSheet
  4. //
  5. // Created by Leo on 2015/4/27.
  6. //
  7. // Copyright (c) 2015-2017 Leo <leodaxia@gmail.com>
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in all
  17. // copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. // SOFTWARE.
  26. #import <UIKit/UIKit.h>
  27. #import "LCActionSheetConfig.h"
  28. @class LCActionSheet;
  29. NS_ASSUME_NONNULL_BEGIN
  30. #pragma mark - LCActionSheet Block
  31. /**
  32. Handle click button.
  33. */
  34. typedef void(^LCActionSheetClickedHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
  35. /**
  36. Handle action sheet will present.
  37. */
  38. typedef void(^LCActionSheetWillPresentHandler)(LCActionSheet *actionSheet);
  39. /**
  40. Handle action sheet did present.
  41. */
  42. typedef void(^LCActionSheetDidPresentHandler)(LCActionSheet *actionSheet);
  43. /**
  44. Handle action sheet will dismiss.
  45. */
  46. typedef void(^LCActionSheetWillDismissHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
  47. /**
  48. Handle action sheet did dismiss.
  49. */
  50. typedef void(^LCActionSheetDidDismissHandler)(LCActionSheet *actionSheet, NSInteger buttonIndex);
  51. #pragma mark - LCActionSheet Delegate
  52. @protocol LCActionSheetDelegate <NSObject>
  53. @optional
  54. /**
  55. Handle click button.
  56. */
  57. - (void)actionSheet:(LCActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
  58. /**
  59. Handle action sheet will present.
  60. */
  61. - (void)willPresentActionSheet:(LCActionSheet *)actionSheet;
  62. /**
  63. Handle action sheet did present.
  64. */
  65. - (void)didPresentActionSheet:(LCActionSheet *)actionSheet;
  66. /**
  67. Handle action sheet will dismiss.
  68. */
  69. - (void)actionSheet:(LCActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;
  70. /**
  71. Handle action sheet did dismiss.
  72. */
  73. - (void)actionSheet:(LCActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;
  74. @end
  75. #pragma mark - LCActionSheet
  76. @interface LCActionSheet : UIView
  77. #pragma mark - Properties
  78. /**
  79. Title.
  80. */
  81. @property (nullable, nonatomic, copy) NSString *title;
  82. /**
  83. Cancel button's title.
  84. */
  85. @property (nullable, nonatomic, copy) NSString *cancelButtonTitle;
  86. /**
  87. Cancel button's index.
  88. */
  89. @property (nonatomic, assign, readonly) NSInteger cancelButtonIndex;
  90. /**
  91. LCActionSheet's delegate.
  92. */
  93. @property (nullable, nonatomic, weak) id<LCActionSheetDelegate> delegate;
  94. /**
  95. Deprecated, use `destructiveButtonIndexSet` instead.
  96. */
  97. @property (nullable, nonatomic, strong) NSIndexSet *redButtonIndexSet __deprecated_msg("Property deprecated. Use `destructiveButtonIndexSet` instead.");
  98. /**
  99. All destructive buttons' set. You should give it the `NSNumber` type items.
  100. */
  101. @property (nullable, nonatomic, strong) NSIndexSet *destructiveButtonIndexSet;
  102. /**
  103. Destructive button's color. Default is RGB(254, 67, 37).
  104. */
  105. @property (nonatomic, strong) UIColor *destructiveButtonColor;
  106. /**
  107. Title's color. Default is `[UIColor blackColor]`.
  108. */
  109. @property (nonatomic, strong) UIColor *titleColor;
  110. /**
  111. Buttons' color, without destructive buttons. Default is `[UIColor blackColor]`.
  112. */
  113. @property (nonatomic, strong) UIColor *buttonColor;
  114. /**
  115. Title's font. Default is `[UIFont systemFontOfSize:14.0f]`.
  116. */
  117. @property (nonatomic, strong) UIFont *titleFont;
  118. /**
  119. All buttons' font. Default is `[UIFont systemFontOfSize:18.0f]`.
  120. */
  121. @property (nonatomic, strong) UIFont *buttonFont;
  122. /**
  123. All buttons' height. Default is 49.0f;
  124. */
  125. @property (nonatomic, assign) CGFloat buttonHeight;
  126. /**
  127. If buttons' bottom view can scrolling. Default is NO.
  128. */
  129. @property (nonatomic, assign, getter=canScrolling) BOOL scrolling;
  130. /**
  131. Visible buttons' count. You have to set `scrolling = YES` if you want to set it.
  132. */
  133. @property (nonatomic, assign) CGFloat visibleButtonCount;
  134. /**
  135. Animation duration. Default is 0.3 seconds.
  136. */
  137. @property (nonatomic, assign) CGFloat animationDuration;
  138. /**
  139. Opacity of dark background. Default is 0.3f.
  140. */
  141. @property (nonatomic, assign) CGFloat darkOpacity;
  142. /**
  143. If you can tap darkView to dismiss. Defalut is NO, you can tap dardView to dismiss.
  144. */
  145. @property (nonatomic, assign) BOOL darkViewNoTaped;
  146. /**
  147. Clear blur effect. Default is NO, don't clear blur effect.
  148. */
  149. @property (nonatomic, assign) BOOL unBlur;
  150. /**
  151. Style of blur effect. Default is `UIBlurEffectStyleExtraLight`. iOS 8.0 +
  152. */
  153. @property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle;
  154. /**
  155. Title's edge insets. Default is `UIEdgeInsetsMake(15.0f, 15.0f, 15.0f, 15.0f)`.
  156. */
  157. @property (nonatomic, assign) UIEdgeInsets titleEdgeInsets;
  158. /**
  159. Cell's separator color. Default is `RGBA(170/255.0f, 170/255.0f, 170/255.0f, 0.5f)`.
  160. */
  161. @property (nonatomic, strong) UIColor *separatorColor;
  162. /**
  163. Auto hide when the device rotated. Default is NO, won't auto hide.
  164. */
  165. @property (nonatomic, assign) BOOL autoHideWhenDeviceRotated;
  166. /**
  167. LCActionSheet clicked handler.
  168. */
  169. @property (nullable, nonatomic, copy) LCActionSheetClickedHandler clickedHandler;
  170. /**
  171. LCActionSheet will present handler.
  172. */
  173. @property (nullable, nonatomic, copy) LCActionSheetWillPresentHandler willPresentHandler;
  174. /**
  175. LCActionSheet did present handler.
  176. */
  177. @property (nullable, nonatomic, copy) LCActionSheetDidPresentHandler didPresentHandler;
  178. /**
  179. LCActionSheet will dismiss handler.
  180. */
  181. @property (nullable, nonatomic, copy) LCActionSheetWillDismissHandler willDismissHandler;
  182. /**
  183. LCActionSheet did dismiss handler.
  184. */
  185. @property (nullable, nonatomic, copy) LCActionSheetDidDismissHandler didDismissHandler;
  186. #pragma mark - Methods
  187. #pragma mark Delegate
  188. /**
  189. Initialize an instance of LCActionSheet (Delegate).
  190. @param title title
  191. @param delegate delegate
  192. @param cancelButtonTitle cancelButtonTitle
  193. @param otherButtonTitles otherButtonTitles
  194. @return An instance of LCActionSheet.
  195. */
  196. + (instancetype)sheetWithTitle:(nullable NSString *)title
  197. delegate:(nullable id<LCActionSheetDelegate>)delegate
  198. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  199. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  200. /**
  201. Initialize an instance of LCActionSheet with title array (Delegate).
  202. @param title title
  203. @param delegate delegate
  204. @param cancelButtonTitle cancelButtonTitle
  205. @param otherButtonTitleArray otherButtonTitleArray
  206. @return An instance of LCActionSheet.
  207. */
  208. + (instancetype)sheetWithTitle:(nullable NSString *)title
  209. delegate:(nullable id<LCActionSheetDelegate>)delegate
  210. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  211. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  212. /**
  213. Initialize an instance of LCActionSheet (Delegate).
  214. @param title title
  215. @param delegate delegate
  216. @param cancelButtonTitle cancelButtonTitle
  217. @param otherButtonTitles otherButtonTitles
  218. @return An instance of LCActionSheet.
  219. */
  220. - (instancetype)initWithTitle:(nullable NSString *)title
  221. delegate:(nullable id<LCActionSheetDelegate>)delegate
  222. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  223. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  224. /**
  225. Initialize an instance of LCActionSheet with title array (Delegate).
  226. @param title title
  227. @param delegate delegate
  228. @param cancelButtonTitle cancelButtonTitle
  229. @param otherButtonTitleArray otherButtonTitleArray
  230. @return An instance of LCActionSheet.
  231. */
  232. - (instancetype)initWithTitle:(nullable NSString *)title
  233. delegate:(nullable id<LCActionSheetDelegate>)delegate
  234. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  235. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  236. #pragma mark Block
  237. /**
  238. Initialize an instance of LCActionSheet (Block).
  239. @param title title
  240. @param cancelButtonTitle cancelButtonTitle
  241. @param clickedHandler clickedHandler
  242. @param otherButtonTitles otherButtonTitles
  243. @return An instance of LCActionSheet.
  244. */
  245. + (instancetype)sheetWithTitle:(nullable NSString *)title
  246. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  247. clicked:(nullable LCActionSheetClickedHandler)clickedHandler
  248. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  249. /**
  250. Initialize an instance of LCActionSheet with title array (Block).
  251. @param title title
  252. @param cancelButtonTitle cancelButtonTitle
  253. @param clickedHandler clickedHandler
  254. @param otherButtonTitleArray otherButtonTitleArray
  255. @return An instance of LCActionSheet.
  256. */
  257. + (instancetype)sheetWithTitle:(nullable NSString *)title
  258. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  259. clicked:(nullable LCActionSheetClickedHandler)clickedHandler
  260. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  261. /**
  262. Initialize an instance of LCActionSheet (Block).
  263. @param title title
  264. @param cancelButtonTitle cancelButtonTitle
  265. @param clickedHandler clickedHandler
  266. @param otherButtonTitles otherButtonTitles
  267. @return An instance of LCActionSheet.
  268. */
  269. - (instancetype)initWithTitle:(nullable NSString *)title
  270. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  271. clicked:(nullable LCActionSheetClickedHandler)clickedHandler
  272. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  273. /**
  274. Initialize an instance of LCActionSheet with title array (Block).
  275. @param title title
  276. @param cancelButtonTitle cancelButtonTitle
  277. @param clickedHandler clickedHandler
  278. @param otherButtonTitleArray otherButtonTitleArray
  279. @return An instance of LCActionSheet.
  280. */
  281. - (instancetype)initWithTitle:(nullable NSString *)title
  282. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  283. clicked:(nullable LCActionSheetClickedHandler)clickedHandler
  284. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  285. /**
  286. Initialize an instance of LCActionSheet (Block).
  287. @param title title
  288. @param cancelButtonTitle cancelButtonTitle
  289. @param didDismissHandler didDismissHandler
  290. @param otherButtonTitles otherButtonTitles
  291. @return An instance of LCActionSheet.
  292. */
  293. + (instancetype)sheetWithTitle:(nullable NSString *)title
  294. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  295. didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
  296. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  297. /**
  298. Initialize an instance of LCActionSheet with title array (Block).
  299. @param title title
  300. @param cancelButtonTitle cancelButtonTitle
  301. @param didDismissHandler didDismissHandler
  302. @param otherButtonTitleArray otherButtonTitleArray
  303. @return An instance of LCActionSheet.
  304. */
  305. + (instancetype)sheetWithTitle:(nullable NSString *)title
  306. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  307. didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
  308. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  309. /**
  310. Initialize an instance of LCActionSheet (Block).
  311. @param title title
  312. @param cancelButtonTitle cancelButtonTitle
  313. @param didDismissHandler didDismissHandler
  314. @param otherButtonTitles otherButtonTitles
  315. @return An instance of LCActionSheet.
  316. */
  317. - (instancetype)initWithTitle:(nullable NSString *)title
  318. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  319. didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
  320. otherButtonTitles:(nullable NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
  321. /**
  322. Initialize an instance of LCActionSheet with title array (Block).
  323. @param title title
  324. @param cancelButtonTitle cancelButtonTitle
  325. @param didDismissHandler didDismissHandler
  326. @param otherButtonTitleArray otherButtonTitleArray
  327. @return An instance of LCActionSheet.
  328. */
  329. - (instancetype)initWithTitle:(nullable NSString *)title
  330. cancelButtonTitle:(nullable NSString *)cancelButtonTitle
  331. didDismiss:(nullable LCActionSheetDidDismissHandler)didDismissHandler
  332. otherButtonTitleArray:(nullable NSArray<NSString *> *)otherButtonTitleArray;
  333. #pragma mark Append & Show
  334. /**
  335. Append buttons with titles.
  336. @param titles titles
  337. */
  338. - (void)appendButtonsWithTitles:(nullable NSString *)titles, ... NS_REQUIRES_NIL_TERMINATION;
  339. /**
  340. Append button at index with title.
  341. @param title title
  342. @param index index
  343. */
  344. - (void)appendButtonWithTitle:(nullable NSString *)title atIndex:(NSInteger)index;
  345. /**
  346. Append buttons at indexSet with titles.
  347. @param titles titles
  348. @param indexes indexes
  349. */
  350. - (void)appendButtonsWithTitles:(NSArray<NSString *> *)titles atIndexes:(NSIndexSet *)indexes;
  351. /**
  352. Show the instance of LCActionSheet.
  353. */
  354. - (void)show;
  355. @end
  356. NS_ASSUME_NONNULL_END