DatePickerAlertView.m 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. //
  2. // DatePickerAlertView.m
  3. // DatePickerAlertView
  4. //
  5. // Created by SNICE on 2018/8/29.
  6. // Copyright © 2018年 G. All rights reserved.
  7. //
  8. #import "DatePickerAlertView.h"
  9. @implementation UIView (Frame)
  10. - (void)setPosition:(CGPoint)point atAnchorPoint:(CGPoint)anchorPoint
  11. {
  12. CGFloat x = point.x - anchorPoint.x * self.frame.size.width;
  13. CGFloat y = point.y - anchorPoint.y * self.frame.size.height;
  14. CGRect frame = self.frame;
  15. frame.origin = CGPointMake(x, y);
  16. self.frame = frame;
  17. }
  18. @end
  19. #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width //屏幕宽
  20. #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height //屏幕高
  21. #define ISIPHONEX \
  22. ^(){\
  23. BOOL iPhoneX = NO;\
  24. if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {\
  25. return iPhoneX;\
  26. }\
  27. if (@available(iOS 11.0, *)) {\
  28. UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];\
  29. if (mainWindow.safeAreaInsets.bottom > 0.0) {\
  30. iPhoneX = YES;\
  31. }\
  32. }\
  33. return iPhoneX;\
  34. }()
  35. #define STATUS_BAR_HEIGHT (ISIPHONEX ? 44.0f : 20.0f)
  36. #define NAVIGATION_BAR_HEIGHT (44.0f)
  37. #define STATUS_AND_NAVIGATION_BAR_HEIGHT ((STATUS_BAR_HEIGHT) + (NAVIGATION_BAR_HEIGHT))
  38. #define k_BOTTOM_SAFE_HEIGHT (CGFloat)(ISIPHONEX ? (34) : (0)) //iPhone X底部home键高度
  39. #define TIPS_ALERT_DURATION 0.25f //动画时长
  40. #define SHOW_DURATION 1.5f //显示时长
  41. @interface TipsAlertView : UIView
  42. @property (nonatomic, strong) NSString *tipsString;
  43. @property (nonatomic, strong, readonly) UILabel *tipsLabel;
  44. @end
  45. @implementation TipsAlertView
  46. + (void)showWithTips:(NSString *)tips {
  47. TipsAlertView *alertView = [[TipsAlertView alloc] init];
  48. alertView.tipsString = tips;
  49. [alertView setPosition:CGPointZero atAnchorPoint:CGPointMake(0, 1)];
  50. [[UIApplication sharedApplication].keyWindow addSubview:alertView];
  51. [alertView show];
  52. }
  53. - (instancetype)init
  54. {
  55. self = [super init];
  56. if (self) {
  57. self.backgroundColor = [UIColor whiteColor];
  58. self.frame = CGRectMake(0, 0, SCREEN_WIDTH, STATUS_AND_NAVIGATION_BAR_HEIGHT);
  59. self.clipsToBounds = YES;
  60. _tipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0f, 0, self.frame.size.width - 30.0f, self.frame.size.height)];
  61. _tipsLabel.font = [UIFont systemFontOfSize:15.0f];
  62. _tipsLabel.textColor = [UIColor redColor];
  63. _tipsLabel.textAlignment = NSTextAlignmentCenter;
  64. _tipsLabel.contentMode = UIViewContentModeBottom;
  65. _tipsLabel.numberOfLines = 0;
  66. _tipsLabel.lineBreakMode = NSLineBreakByCharWrapping;
  67. [self addSubview:_tipsLabel];
  68. UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
  69. tapGR.numberOfTapsRequired = 1;
  70. tapGR.numberOfTouchesRequired = 1;
  71. [self addGestureRecognizer:tapGR];
  72. }
  73. return self;
  74. }
  75. - (void)setTipsString:(NSString *)tipsString {
  76. _tipsString = tipsString;
  77. _tipsLabel.text = tipsString;
  78. [_tipsLabel sizeToFit];
  79. [_tipsLabel setPosition:CGPointMake(self.frame.size.width / 2, self.frame.size.height - 10.0f) atAnchorPoint:CGPointMake(0.5, 1)];
  80. }
  81. - (void)show {
  82. [UIView animateWithDuration:TIPS_ALERT_DURATION animations:^{
  83. [self setPosition:CGPointZero atAnchorPoint:CGPointZero];
  84. } completion:^(BOOL finished) {
  85. [self performSelector:@selector(hide) withObject:nil afterDelay:SHOW_DURATION];
  86. }];
  87. }
  88. - (void)hide {
  89. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  90. [UIView animateWithDuration:TIPS_ALERT_DURATION animations:^{
  91. [self setPosition:CGPointZero atAnchorPoint:CGPointMake(0, 1)];
  92. } completion:^(BOOL finished) {
  93. [self removeFromSuperview];
  94. }];
  95. }
  96. @end
  97. #define HexColor(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0f green:((c>>8)&0xFF)/255.0f blue:(c&0xFF)/255.0f alpha:1.0f]
  98. #define TEXT_COLOR HexColor(0x111111) //文本默认显示颜色
  99. #define HIGHLIGHTED_COLOR HexColor(0x05CFAB) //文本高亮显示颜色
  100. #define BACKGROUNG_COLOR HexColor(0xf5f7f9)
  101. #define TAG_COLOR HexColor(0x999999)
  102. #define ANIMATION_DURATION 0.5f //动画时长
  103. #define WINDOWVIEW_HEIGHT 300.0f //显示视图高度
  104. #define PICKERVIEW_HEIGHT 200.0f //时间选择器高度
  105. #define MARGIN 15.0f //边距
  106. #define LABEL_WIDTH 40.0f //"至"label宽度
  107. #define TEXTFIELD_WIDTH ((SCREEN_WIDTH - MARGIN * 2.0f - LABEL_WIDTH) / 2.0f) //textfield宽度
  108. #define TEXTFIELD_HEIGHT 30.0f //textfield高度
  109. #define BOTTOM_BUTTON_HEIGHT 40.0f //底部按钮高度
  110. #define BOTTOM_BUTTON_WIDTH (SCREEN_WIDTH / 2.0f) //底部按钮宽度
  111. #define FROM_TIME_BUTTON_PLACEHOLDER @"Start time"
  112. #define TO_TIME_BUTTON_PLACEHOLDER @"End time"
  113. #define FROM_TIME_MORE_THEM_TO_TIME_TIPS @"The start time cannot be greater than the end time"
  114. #define TO_TIME_LESS_THEM_FROM_TIME_TIPS @"End time cannot be less than start time"
  115. #define TO_TIME_IS_EMPTY_TIPS @"Please select an end time"
  116. #define FROM_TIME_TO_TIME_CANNOT_EXCEED_TIPS @"Start time and end time cannot be more than 30 days"
  117. @interface DatePickerAlertView() <UITextFieldDelegate>
  118. @property (nonatomic, strong) UIWindow *window; //window
  119. @property (nonatomic, strong) UIView *blackMask; //黑色笼罩
  120. @property (nonatomic, strong) UIView *windowView; //显示view
  121. @property (nonatomic, strong) UIDatePicker *datePicker; //时间选择器
  122. @property (nonatomic, strong) UIButton *fromTimeButton; //开始时间按钮
  123. @property (nonatomic, strong) UIButton *toTimeButton; //结束时间按钮
  124. @property (nonatomic, strong) UIButton *resetButton; //重置按钮
  125. @property (nonatomic, strong) UIButton *ensureButton; //确定按钮
  126. @property (nonatomic, strong) NSString *dateFormat; //时间格式显示
  127. @property (nonatomic, assign) UIDatePickerMode datePickerMode; //日期控件显示类型
  128. @property (nonatomic, strong) NSDate *fromDate; //开始时间
  129. @property (nonatomic, strong) NSDate *toDate; //结束时间
  130. @property (nonatomic, strong) NSString *errorStr; //错误提示
  131. @property (nonatomic, strong) void (^didSelectDate)(NSDate *fromDate, NSDate *toDate);
  132. @property (nonatomic,strong) void (^error)(NSString *error);
  133. @end
  134. @implementation DatePickerAlertView
  135. + (void)showDatePickerAlertViewWithSelectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion failure:(void (^)(NSString *))failure{
  136. [self showDatePickerAlertViewWithDateFormat:D_yyyy_MM_dd datePickerMode:UIDatePickerModeDate selectCompletion:selectCompletion failure:failure];
  137. }
  138. + (void)showDatePickerAlertViewWithDateFormat:(NSString *)dateFormat datePickerMode:(UIDatePickerMode)datePickerMode selectCompletion:(void (^)(NSDate *fromDate, NSDate *toDate))selectCompletion failure:(void (^)(NSString *))failure {
  139. DatePickerAlertView *alertView = [[DatePickerAlertView alloc] init];
  140. alertView.didSelectDate = ^(NSDate *fromDate, NSDate *toDate) {
  141. if (selectCompletion) selectCompletion(fromDate, toDate);
  142. };
  143. alertView.error = ^(NSString *error) {
  144. if (failure) {
  145. failure(error);
  146. }
  147. };
  148. alertView.dateFormat = dateFormat;
  149. alertView.datePickerMode = datePickerMode;
  150. [alertView resetAction];
  151. [alertView show];
  152. }
  153. - (instancetype)init
  154. {
  155. self = [super init];
  156. if (self) {
  157. self.frame = [UIScreen mainScreen].bounds;
  158. self.backgroundColor = [UIColor clearColor];
  159. self.clipsToBounds = YES;
  160. [self addSubview:self.blackMask];
  161. [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT) atAnchorPoint:CGPointZero];
  162. [self addSubview:self.windowView];
  163. [self.fromTimeButton setPosition:CGPointMake(MARGIN, MARGIN) atAnchorPoint:CGPointZero];
  164. [self.windowView addSubview:self.fromTimeButton];
  165. [self.toTimeButton setPosition:CGPointMake(SCREEN_WIDTH - MARGIN, MARGIN) atAnchorPoint:CGPointMake(1, 0)];
  166. [self.windowView addSubview:self.toTimeButton];
  167. [self.datePicker setPosition:CGPointMake(0, CGRectGetMaxY(self.fromTimeButton.frame) + MARGIN) atAnchorPoint:CGPointZero];
  168. [self.windowView addSubview:self.datePicker];
  169. [self.resetButton setPosition:CGPointMake(0, WINDOWVIEW_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
  170. [self.windowView addSubview:self.resetButton];
  171. [self.ensureButton setPosition:CGPointMake(SCREEN_WIDTH, WINDOWVIEW_HEIGHT) atAnchorPoint:CGPointMake(1, 1)];
  172. [self.windowView addSubview:self.ensureButton];
  173. UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
  174. tapGR.numberOfTapsRequired = 1;
  175. tapGR.numberOfTouchesRequired = 1;
  176. [self addGestureRecognizer:tapGR];
  177. _dateFormat = D_yyyy_MM_dd;
  178. [self resetAction];
  179. }
  180. return self;
  181. }
  182. - (void)resetAction {
  183. self.fromDate = [NSDate date];
  184. [self.datePicker setDate:self.fromDate animated:YES];
  185. self.fromTimeButton.selected = YES;
  186. [self.fromTimeButton setTitle:[self.class dateStringWithDate:_fromDate format:_dateFormat] forState:UIControlStateNormal];
  187. self.toDate = nil;
  188. self.toTimeButton.selected = NO;
  189. [self.toTimeButton setTitle:TO_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
  190. }
  191. - (void)ensureAction {
  192. if (!self.toDate) {
  193. self.errorStr = TO_TIME_IS_EMPTY_TIPS;
  194. // [TipsAlertView showWithTips:TO_TIME_IS_EMPTY_TIPS];
  195. return ;
  196. }
  197. if (self.didSelectDate) {
  198. self.didSelectDate(self.fromDate, self.toDate);
  199. }
  200. [self hide];
  201. }
  202. - (void)timeButtonAction {
  203. self.toTimeButton.selected = self.fromTimeButton.selected;
  204. self.fromTimeButton.selected = !self.fromTimeButton.selected;
  205. }
  206. - (void)dataPickerChanged:(UIDatePicker *)datePicker {
  207. NSString *dateString = [self.class dateStringWithDate:datePicker.date format:self.dateFormat];
  208. if (self.fromTimeButton.selected) {
  209. if ([self judgeDateIsErrorWithFromDate:datePicker.date toDate:self.toDate]) {
  210. [datePicker setDate:self.fromDate animated:YES];
  211. // [TipsAlertView showWithTips:FROM_TIME_MORE_THEM_TO_TIME_TIPS];
  212. // if (_pickerDateErrorBlock) {
  213. // _pickerDateErrorBlock(FROM_TIME_MORE_THEM_TO_TIME_TIPS);
  214. // }
  215. self.errorStr = FROM_TIME_MORE_THEM_TO_TIME_TIPS;
  216. return ;
  217. }
  218. self.fromDate = datePicker.date;
  219. [self.fromTimeButton setTitle:dateString forState:UIControlStateNormal];
  220. } else {
  221. if ([self judgeDateIsErrorWithFromDate:self.fromDate toDate:datePicker.date]) {
  222. [datePicker setDate:self.toDate ? self.toDate : self.fromDate animated:YES];
  223. // [TipsAlertView showWithTips:TO_TIME_LESS_THEM_FROM_TIME_TIPS];
  224. // if (_pickerDateErrorBlock) {
  225. // _pickerDateErrorBlock(TO_TIME_LESS_THEM_FROM_TIME_TIPS);
  226. // }
  227. self.errorStr = TO_TIME_LESS_THEM_FROM_TIME_TIPS;
  228. return ;
  229. }
  230. //超过三十天,只做提示 ,不返回了
  231. if ([self judgeDateIsMoreThanWithFromDate:self.fromDate toDate:datePicker.date]) {
  232. // [datePicker setDate:self.toDate ? self.toDate : self.fromDate animated:YES];
  233. // [TipsAlertView showWithTips:FROM_TIME_TO_TIME_CANNOT_EXCEED_TIPS];
  234. // if (_pickerDateErrorBlock) {
  235. // _pickerDateErrorBlock(FROM_TIME_TO_TIME_CANNOT_EXCEED_TIPS);
  236. // }
  237. self.errorStr = FROM_TIME_TO_TIME_CANNOT_EXCEED_TIPS;
  238. return;
  239. }
  240. self.toDate = datePicker.date;
  241. [self.toTimeButton setTitle:dateString forState:UIControlStateNormal];
  242. }
  243. }
  244. + (NSString *)dateStringWithDate:(NSDate *)date format:(NSString *)format {
  245. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  246. formatter.timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
  247. formatter.dateFormat = format;
  248. return [formatter stringFromDate:date];
  249. }
  250. - (BOOL)judgeDateIsErrorWithFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate {
  251. if (fromDate && toDate && fromDate.timeIntervalSinceReferenceDate >= toDate.timeIntervalSinceReferenceDate) return YES;
  252. return NO;
  253. }
  254. //判断时间间隔是否大于三十天
  255. - (BOOL)judgeDateIsMoreThanWithFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate {
  256. NSTimeInterval time = [toDate timeIntervalSinceDate:fromDate];
  257. int days = (int) (time / (3600 * 24)+ 0.5) ; //四舍五入
  258. if (fromDate && toDate && days > 30) return YES;
  259. return NO;
  260. }
  261. - (void)show {
  262. [self.window addSubview:self];
  263. [UIView animateWithDuration:ANIMATION_DURATION animations:^{
  264. self.blackMask.alpha = 0.2f;
  265. [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT - k_BOTTOM_SAFE_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
  266. } completion:^(BOOL finished) {
  267. }];
  268. }
  269. - (void)hide {
  270. [UIView animateWithDuration:ANIMATION_DURATION animations:^{
  271. self.blackMask.alpha = 0.0f;
  272. [self.windowView setPosition:CGPointMake(0, SCREEN_HEIGHT) atAnchorPoint:CGPointMake(0, 0)];
  273. } completion:^(BOOL finished) {
  274. [self removeFromSuperview];
  275. }];
  276. }
  277. #pragma mark - setter method
  278. - (void)setDatePickerMode:(UIDatePickerMode)datePickerMode {
  279. _datePickerMode = datePickerMode;
  280. self.datePicker.datePickerMode = datePickerMode;
  281. }
  282. #pragma mark - Lazy loading
  283. - (UIWindow *)window {
  284. if (!_window) {
  285. _window = [UIApplication sharedApplication].keyWindow;
  286. }
  287. return _window;
  288. }
  289. - (UIView *)blackMask {
  290. if (!_blackMask) {
  291. _blackMask = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  292. _blackMask.clipsToBounds = YES;
  293. _blackMask.alpha = 0.0f;
  294. _blackMask.backgroundColor = [UIColor blackColor];
  295. }
  296. return _blackMask;
  297. }
  298. - (UIView *)windowView {
  299. if (!_windowView) {
  300. _windowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, WINDOWVIEW_HEIGHT)];
  301. _windowView.backgroundColor = [UIColor whiteColor];
  302. _windowView.clipsToBounds = YES;
  303. }
  304. return _windowView;
  305. }
  306. - (UIButton *)fromTimeButton {
  307. if (!_fromTimeButton) {
  308. _fromTimeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT)];
  309. [_fromTimeButton setTitle:FROM_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
  310. [_fromTimeButton setTitleColor:TAG_COLOR forState:UIControlStateNormal];
  311. [_fromTimeButton setTitleColor:[UIColor colorWithRed:87/255.0 green:63/255.0 blue:149/255.0 alpha:1.0] forState:UIControlStateSelected];
  312. //[_fromTimeButton setTitleColor:HIGHLIGHTED_COLOR forState:UIControlStateSelected];
  313. _fromTimeButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
  314. [_fromTimeButton addTarget:self action:@selector(timeButtonAction) forControlEvents:UIControlEventTouchUpInside];
  315. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, 1.0f)];
  316. lineView.backgroundColor = [UIColor blackColor];
  317. [lineView setPosition:CGPointMake(0, TEXTFIELD_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
  318. [_fromTimeButton addSubview:lineView];
  319. }
  320. return _fromTimeButton;
  321. }
  322. - (UIButton *)toTimeButton {
  323. if (!_toTimeButton) {
  324. _toTimeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, TEXTFIELD_HEIGHT)];
  325. [_toTimeButton setTitle:TO_TIME_BUTTON_PLACEHOLDER forState:UIControlStateNormal];
  326. [_toTimeButton setTitleColor:TAG_COLOR forState:UIControlStateNormal];
  327. [_toTimeButton setTitleColor:[UIColor colorWithRed:87/255.0 green:63/255.0 blue:149/255.0 alpha:1.0] forState:UIControlStateSelected];
  328. _toTimeButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
  329. [_toTimeButton addTarget:self action:@selector(timeButtonAction) forControlEvents:UIControlEventTouchUpInside];
  330. UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TEXTFIELD_WIDTH, 1.0f)];
  331. lineView.backgroundColor = [UIColor blackColor];
  332. [lineView setPosition:CGPointMake(0, TEXTFIELD_HEIGHT) atAnchorPoint:CGPointMake(0, 1)];
  333. [_toTimeButton addSubview:lineView];
  334. }
  335. return _toTimeButton;
  336. }
  337. - (UIDatePicker *)datePicker {
  338. if (!_datePicker) {
  339. //创建一个UIPickView对象
  340. _datePicker = [[UIDatePicker alloc] init];
  341. _datePicker.frame = CGRectMake(0, 0, SCREEN_WIDTH, PICKERVIEW_HEIGHT);
  342. //设置背景颜色
  343. _datePicker.backgroundColor = [UIColor whiteColor];
  344. //设置本地化支持的语言(在此是英文)
  345. _datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
  346. //显示方式是只显示年月日
  347. _datePicker.datePickerMode = UIDatePickerModeDate;
  348. //监听变化
  349. [_datePicker addTarget:self action:@selector(dataPickerChanged:) forControlEvents:UIControlEventValueChanged];
  350. }
  351. return _datePicker;
  352. }
  353. - (UIButton *)resetButton {
  354. if (!_resetButton) {
  355. _resetButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT)];
  356. [_resetButton setTitle:@"重设" forState:UIControlStateNormal];
  357. [_resetButton setTitleColor:TEXT_COLOR forState:UIControlStateNormal];
  358. _resetButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
  359. _resetButton.backgroundColor = BACKGROUNG_COLOR;
  360. [_resetButton addTarget:self action:@selector(resetAction) forControlEvents:UIControlEventTouchUpInside];
  361. }
  362. return _resetButton;
  363. }
  364. - (UIButton *)ensureButton {
  365. if (!_ensureButton) {
  366. _ensureButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_HEIGHT)];
  367. [_ensureButton setTitle:@"确认" forState:UIControlStateNormal];
  368. [_ensureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  369. _ensureButton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
  370. //_ensureButton.backgroundColor = HIGHLIGHTED_COLOR;
  371. // UIColor(hexString: "#573F95")
  372. _ensureButton.backgroundColor = [UIColor colorWithRed:87/255.0 green:63/255.0 blue:149/255.0 alpha:1.0];
  373. [_ensureButton addTarget:self action:@selector(ensureAction) forControlEvents:UIControlEventTouchUpInside];
  374. }
  375. return _ensureButton;
  376. }
  377. - (void)setErrorStr:(NSString *)errorStr{
  378. _errorStr = errorStr;
  379. if (self.error) {
  380. if (errorStr) {
  381. self.error(errorStr);
  382. }
  383. }
  384. }
  385. @end