You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.6 KiB

  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, strong) 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 alloc] init];
  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. return (type && (strcmp(type, FLEXEncodeClass(NSDate)) == 0)) || [value isKindOfClass:[NSDate class]];
  50. }
  51. @end