/MercyMap/Tool/IQKeyBoardManager/IQToolbar/IQUIView+IQKeyboardToolbar.h

https://gitlab.com/RainGu/mercymap · C Header · 357 lines · 34 code · 49 blank · 274 comment · 0 complexity · 4689d913f94ae43c7d4af7de0df06a12 MD5 · raw file

  1. //
  2. // UIView+IQToolbar.h
  3. // https://github.com/hackiftekhar/IQKeyboardManager
  4. // Copyright (c) 2013-15 Iftekhar Qurashi.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. #import <UIKit/UIView.h>
  24. @class UIBarButtonItem;
  25. /**
  26. UIView category methods to add IQToolbar on UIKeyboard.
  27. */
  28. @interface UIView (IQToolbarAddition)
  29. ///-------------------------
  30. /// @name Title and Distance
  31. ///-------------------------
  32. /**
  33. If shouldHideTitle is YES, then title will not be added to the toolbar. Default to NO.
  34. */
  35. @property (assign, nonatomic) BOOL shouldHideTitle;
  36. ///-----------------------------------------
  37. /// @name Customised Invocation Registration
  38. ///-----------------------------------------
  39. /**
  40. Additional target & action to do get callback action. Note that setting custom `previous` selector doesn't affect native `previous` functionality, this is just used to notifiy user to do additional work according to need.
  41. @param target Target object.
  42. @param action Target Selector.
  43. */
  44. -(void)setCustomPreviousTarget:(nullable id)target action:(nullable SEL)action;
  45. /**
  46. Additional target & action to do get callback action. Note that setting custom `next` selector doesn't affect native `next` functionality, this is just used to notifiy user to do additional work according to need.
  47. @param target Target object.
  48. @param action Target Selector.
  49. */
  50. -(void)setCustomNextTarget:(nullable id)target action:(nullable SEL)action;
  51. /**
  52. Additional target & action to do get callback action. Note that setting custom `done` selector doesn't affect native `done` functionality, this is just used to notifiy user to do additional work according to need.
  53. @param target Target object.
  54. @param action Target Selector.
  55. */
  56. -(void)setCustomDoneTarget:(nullable id)target action:(nullable SEL)action;
  57. /**
  58. Customized Invocation to be called on previous arrow action. previousInvocation is internally created using setCustomPreviousTarget: method.
  59. */
  60. @property (nullable, strong, nonatomic) NSInvocation *previousInvocation;
  61. /**
  62. Customized Invocation to be called on next arrow action. nextInvocation is internally created using setCustomNextTarget: method.
  63. */
  64. @property (nullable, strong, nonatomic) NSInvocation *nextInvocation;
  65. /**
  66. Customized Invocation to be called on done action. doneInvocation is internally created using setCustomDoneTarget: method.
  67. */
  68. @property (nullable, strong, nonatomic) NSInvocation *doneInvocation;
  69. ///------------
  70. /// @name Done
  71. ///------------
  72. /**
  73. Helper function to add Done button on keyboard.
  74. @param target Target object for selector.
  75. @param action Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  76. */
  77. - (void)addDoneOnKeyboardWithTarget:(nullable id)target action:(nullable SEL)action;
  78. /**
  79. Helper function to add Done button on keyboard.
  80. @param target Target object for selector.
  81. @param action Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  82. @param titleText text to show as title in IQToolbar'.
  83. */
  84. - (void)addDoneOnKeyboardWithTarget:(nullable id)target action:(nullable SEL)action titleText:(nullable NSString*)titleText;
  85. /**
  86. Helper function to add Done button on keyboard.
  87. @param target Target object for selector.
  88. @param action Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  89. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  90. */
  91. - (void)addDoneOnKeyboardWithTarget:(nullable id)target action:(nullable SEL)action shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  92. ///------------
  93. /// @name Right
  94. ///------------
  95. /**
  96. Helper function to add Right button on keyboard.
  97. @param text Title for rightBarButtonItem, usually 'Done'.
  98. @param target Target object for selector.
  99. @param action Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  100. */
  101. - (void)addRightButtonOnKeyboardWithText:(nullable NSString*)text target:(nullable id)target action:(nullable SEL)action;
  102. /**
  103. Helper function to add Right button on keyboard.
  104. @param text Title for rightBarButtonItem, usually 'Done'.
  105. @param target Target object for selector.
  106. @param action Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  107. @param titleText text to show as title in IQToolbar'.
  108. */
  109. - (void)addRightButtonOnKeyboardWithText:(nullable NSString*)text target:(nullable id)target action:(nullable SEL)action titleText:(nullable NSString*)titleText;
  110. /**
  111. Helper function to add Right button on keyboard.
  112. @param text Title for rightBarButtonItem, usually 'Done'.
  113. @param target Target object for selector.
  114. @param action Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  115. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  116. */
  117. - (void)addRightButtonOnKeyboardWithText:(nullable NSString*)text target:(nullable id)target action:(nullable SEL)action shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  118. /**
  119. Helper function to add Right button on keyboard.
  120. @param image Image icon to use as right button.
  121. @param target Target object for selector.
  122. @param action Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  123. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  124. */
  125. - (void)addRightButtonOnKeyboardWithImage:(nullable UIImage*)image target:(nullable id)target action:(nullable SEL)action shouldShowPlaceholder:(BOOL)showPlaceholder;
  126. /**
  127. Helper function to add Right button on keyboard.
  128. @param image Image icon to use as right button.
  129. @param target Target object for selector.
  130. @param action Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  131. @param titleText text to show as title in IQToolbar'.
  132. */
  133. - (void)addRightButtonOnKeyboardWithImage:(nullable UIImage*)image target:(nullable id)target action:(nullable SEL)action titleText:(nullable NSString*)titleText;
  134. ///------------------
  135. /// @name Cancel/Done
  136. ///------------------
  137. /**
  138. Helper function to add Cancel and Done button on keyboard.
  139. @param target Target object for selector.
  140. @param cancelAction Cancel button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  141. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  142. */
  143. - (void)addCancelDoneOnKeyboardWithTarget:(nullable id)target cancelAction:(nullable SEL)cancelAction doneAction:(nullable SEL)doneAction;
  144. /**
  145. Helper function to add Cancel and Done button on keyboard.
  146. @param target Target object for selector.
  147. @param cancelAction Cancel button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  148. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  149. @param titleText text to show as title in IQToolbar'.
  150. */
  151. - (void)addCancelDoneOnKeyboardWithTarget:(nullable id)target cancelAction:(nullable SEL)cancelAction doneAction:(nullable SEL)doneAction titleText:(nullable NSString*)titleText;
  152. /**
  153. Helper function to add Cancel and Done button on keyboard.
  154. @param target Target object for selector.
  155. @param cancelAction Cancel button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  156. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  157. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  158. */
  159. - (void)addCancelDoneOnKeyboardWithTarget:(nullable id)target cancelAction:(nullable SEL)cancelAction doneAction:(nullable SEL)doneAction shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  160. ///-----------------
  161. /// @name Right/Left
  162. ///-----------------
  163. /**
  164. Helper function to add Left and Right button on keyboard.
  165. @param target Target object for selector.
  166. @param leftButtonTitle Title for leftBarButtonItem, usually 'Cancel'.
  167. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  168. @param leftButtonAction Left button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  169. @param rightButtonAction Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  170. */
  171. - (void)addLeftRightOnKeyboardWithTarget:(nullable id)target leftButtonTitle:(nullable NSString*)leftButtonTitle rightButtonTitle:(nullable NSString*)rightButtonTitle leftButtonAction:(nullable SEL)leftButtonAction rightButtonAction:(nullable SEL)rightButtonAction;
  172. /**
  173. Helper function to add Left and Right button on keyboard.
  174. @param target Target object for selector.
  175. @param leftButtonTitle Title for leftBarButtonItem, usually 'Cancel'.
  176. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  177. @param leftButtonAction Left button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  178. @param rightButtonAction Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  179. @param titleText text to show as title in IQToolbar'.
  180. */
  181. - (void)addLeftRightOnKeyboardWithTarget:(nullable id)target leftButtonTitle:(nullable NSString*)leftButtonTitle rightButtonTitle:(nullable NSString*)rightButtonTitle leftButtonAction:(nullable SEL)leftButtonAction rightButtonAction:(nullable SEL)rightButtonAction titleText:(nullable NSString*)titleText;
  182. /**
  183. Helper function to add Left and Right button on keyboard.
  184. @param target Target object for selector.
  185. @param leftButtonTitle Title for leftBarButtonItem, usually 'Cancel'.
  186. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  187. @param leftButtonAction Left button action name. Usually 'cancelAction:(IQBarButtonItem*)item'.
  188. @param rightButtonAction Right button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  189. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  190. */
  191. - (void)addLeftRightOnKeyboardWithTarget:(nullable id)target leftButtonTitle:(nullable NSString*)leftButtonTitle rightButtonTitle:(nullable NSString*)rightButtonTitle leftButtonAction:(nullable SEL)leftButtonAction rightButtonAction:(nullable SEL)rightButtonAction shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  192. ///-------------------------
  193. /// @name Previous/Next/Done
  194. ///-------------------------
  195. /**
  196. Helper function to add ArrowNextPrevious and Done button on keyboard.
  197. @param target Target object for selector.
  198. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  199. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  200. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  201. */
  202. - (void)addPreviousNextDoneOnKeyboardWithTarget:(nullable id)target previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction doneAction:(nullable SEL)doneAction;
  203. /**
  204. Helper function to add ArrowNextPrevious and Done button on keyboard.
  205. @param target Target object for selector.
  206. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  207. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  208. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  209. @param titleText text to show as title in IQToolbar'.
  210. */
  211. - (void)addPreviousNextDoneOnKeyboardWithTarget:(nullable id)target previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction doneAction:(nullable SEL)doneAction titleText:(nullable NSString*)titleText;
  212. /**
  213. Helper function to add ArrowNextPrevious and Done button on keyboard.
  214. @param target Target object for selector.
  215. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  216. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  217. @param doneAction Done button action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  218. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  219. */
  220. - (void)addPreviousNextDoneOnKeyboardWithTarget:(nullable id)target previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction doneAction:(nullable SEL)doneAction shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  221. ///--------------------------
  222. /// @name Previous/Next/Right
  223. ///--------------------------
  224. /**
  225. Helper function to add ArrowNextPrevious and Right button on keyboard.
  226. @param target Target object for selector.
  227. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  228. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  229. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  230. @param rightButtonAction RightBarButton action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  231. */
  232. - (void)addPreviousNextRightOnKeyboardWithTarget:(nullable id)target rightButtonTitle:(nullable NSString*)rightButtonTitle previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction rightButtonAction:(nullable SEL)rightButtonAction;
  233. /**
  234. Helper function to add ArrowNextPrevious and Right button on keyboard.
  235. @param target Target object for selector.
  236. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  237. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  238. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  239. @param rightButtonAction RightBarButton action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  240. @param titleText text to show as title in IQToolbar'.
  241. */
  242. - (void)addPreviousNextRightOnKeyboardWithTarget:(nullable id)target rightButtonTitle:(nullable NSString*)rightButtonTitle previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction rightButtonAction:(nullable SEL)rightButtonAction titleText:(nullable NSString*)titleText;
  243. /**
  244. Helper function to add ArrowNextPrevious and Right button on keyboard.
  245. @param target Target object for selector.
  246. @param rightButtonTitle Title for rightBarButtonItem, usually 'Done'.
  247. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  248. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  249. @param rightButtonAction RightBarButton action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  250. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  251. */
  252. - (void)addPreviousNextRightOnKeyboardWithTarget:(nullable id)target rightButtonTitle:(nullable NSString*)rightButtonTitle previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction rightButtonAction:(nullable SEL)rightButtonAction shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  253. /**
  254. Helper function to add ArrowNextPrevious and Right button on keyboard.
  255. @param target Target object for selector.
  256. @param rightButtonImage Image icon to use as rightBarButtonItem.
  257. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  258. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  259. @param rightButtonAction RightBarButton action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  260. @param titleText text to show as title in IQToolbar'.
  261. */
  262. - (void)addPreviousNextRightOnKeyboardWithTarget:(nullable id)target rightButtonImage:(nullable UIImage*)rightButtonImage previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction rightButtonAction:(nullable SEL)rightButtonAction titleText:(nullable NSString*)titleText;
  263. /**
  264. Helper function to add ArrowNextPrevious and Right button on keyboard.
  265. @param target Target object for selector.
  266. @param rightButtonImage Image icon to use as rightBarButtonItem.
  267. @param previousAction Previous button action name. Usually 'previousAction:(id)item'.
  268. @param nextAction Next button action name. Usually 'nextAction:(id)item'.
  269. @param rightButtonAction RightBarButton action name. Usually 'doneAction:(IQBarButtonItem*)item'.
  270. @param shouldShowPlaceholder A boolean to indicate whether to show textField placeholder on IQToolbar'.
  271. */
  272. - (void)addPreviousNextRightOnKeyboardWithTarget:(nullable id)target rightButtonImage:(nullable UIImage*)rightButtonImage previousAction:(nullable SEL)previousAction nextAction:(nullable SEL)nextAction rightButtonAction:(nullable SEL)rightButtonAction shouldShowPlaceholder:(BOOL)shouldShowPlaceholder;
  273. ///-----------------------------------
  274. /// @name Enable/Disable Previous/Next
  275. ///-----------------------------------
  276. /**
  277. Helper function to enable and disable previous next buttons.
  278. @param isPreviousEnabled BOOL to enable/disable previous button on keyboard.
  279. @param isNextEnabled BOOL to enable/disable next button on keyboard..
  280. */
  281. - (void)setEnablePrevious:(BOOL)isPreviousEnabled next:(BOOL)isNextEnabled;
  282. @end