FLEXArgumentInputDateView.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // FLEXArgumentInputDataView.m
  3. // Flipboard
  4. //
  5. // Created by Daniel Rodriguez Troitino on 2/14/15.
  6. // Copyright (c) 2015 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXArgumentInputDateView.h"
  9. #import "FLEXRuntimeUtility.h"
  10. @interface FLEXArgumentInputDateView ()
  11. @property (nonatomic) UIDatePicker *datePicker;
  12. @end
  13. @implementation FLEXArgumentInputDateView
  14. - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding
  15. {
  16. self = [super initWithArgumentTypeEncoding:typeEncoding];
  17. if (self) {
  18. self.datePicker = [UIDatePicker new];
  19. self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
  20. // Using UTC, because that's what the NSDate description prints
  21. self.datePicker.calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
  22. self.datePicker.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
  23. [self addSubview:self.datePicker];
  24. }
  25. return self;
  26. }
  27. - (void)setInputValue:(id)inputValue
  28. {
  29. if ([inputValue isKindOfClass:[NSDate class]]) {
  30. self.datePicker.date = inputValue;
  31. }
  32. }
  33. - (id)inputValue
  34. {
  35. return self.datePicker.date;
  36. }
  37. - (void)layoutSubviews
  38. {
  39. [super layoutSubviews];
  40. self.datePicker.frame = self.bounds;
  41. }
  42. - (CGSize)sizeThatFits:(CGSize)size
  43. {
  44. CGFloat height = [self.datePicker sizeThatFits:size].height;
  45. return CGSizeMake(size.width, height);
  46. }
  47. + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value
  48. {
  49. NSParameterAssert(type);
  50. return strcmp(type, FLEXEncodeClass(NSDate)) == 0;
  51. }
  52. @end