DatePikerView.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // DatePikerView.m
  3. // BankQueuingSystem
  4. //
  5. // Created by 宋伟 on 15/6/10.
  6. // Copyright (c) 2015年 com.team.bankQueuing. All rights reserved.
  7. //
  8. #import "DatePikerView.h"
  9. @interface DatePikerView ()
  10. @property (copy, nonatomic) void(^confirmBlock)(NSDate *date);
  11. @property (copy, nonatomic) void(^cancelBlock)(void);
  12. @end
  13. @implementation DatePikerView
  14. static UINib *DatePikerViewNib = nil;
  15. + (instancetype)datePikerView{
  16. if (DatePikerViewNib == nil) {
  17. DatePikerViewNib = [UINib nibWithNibName:@"DatePikerView" bundle:nil];
  18. }
  19. DatePikerView *alert = [[DatePikerViewNib instantiateWithOwner:nil options:nil] lastObject];
  20. return alert;
  21. }
  22. + (instancetype)initWithDate:(NSDate *)date
  23. confirm:(void(^)(NSDate *date))confirmBlock
  24. cancle:(void(^)(void))cancleBlock{
  25. DatePikerView *alert = [self datePikerView];
  26. [alert setGesture:YES];
  27. [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260)];
  28. if (date == nil) {
  29. date = [NSDate date];
  30. }
  31. [alert.datePickerView setDate:date];
  32. [alert setConfirmBlock:confirmBlock];
  33. [alert setCancelBlock:cancleBlock];
  34. [alert setBackgroundColor:[UIColor whiteColor]];
  35. return alert;
  36. }
  37. - (CGPoint)centerWithAnimation:(AlertAnimation)animation{
  38. if (animation == kAlertAnimationNone) {
  39. CGRect bounds = [UIScreen mainScreen].bounds;
  40. CGPoint center = CGPointZero;
  41. center.x = bounds.size.width/2;
  42. if (IOS7_OR_LATER) {
  43. center.y = bounds.size.height - self.bounds.size.height/2;
  44. }else{
  45. center.y = bounds.size.height - self.bounds.size.height/2 - 20;
  46. }
  47. return center;
  48. }
  49. return [super centerWithAnimation:animation];
  50. }
  51. - (IBAction)cancelButtonAction:(id)sender {
  52. [self dismissWithAnimation:kAlertAnimationBottom];
  53. if (self.cancelBlock) {
  54. self.cancelBlock();
  55. }
  56. }
  57. - (IBAction)calculateButtonAction:(id)sender {
  58. [self dismissWithAnimation:kAlertAnimationBottom];
  59. if (self.confirmBlock) {
  60. self.confirmBlock(self.datePickerView.date);
  61. }
  62. }
  63. @end