PGDatePickerView.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // PGDatePickerView.m
  3. //
  4. // Created by piggybear on 2017/7/25.
  5. // Copyright © 2017年 piggybear. All rights reserved.
  6. //
  7. #import "PGDatePickerView.h"
  8. #import "UIColor+PGHex.h"
  9. @interface PGDatePickerView()
  10. @property (nonatomic, weak) UILabel *label;
  11. @end
  12. @implementation PGDatePickerView
  13. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  14. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  15. self.selectionStyle = UITableViewCellSelectionStyleNone;
  16. }
  17. return self;
  18. }
  19. - (void)layoutSubviews {
  20. [super layoutSubviews];
  21. CGSize size = [self.content sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]}];
  22. self.label.frame = (CGRect){{self.contentView.bounds.size.width / 2 - size.width / 2,
  23. self.contentView.bounds.size.height / 2 - size.height / 2}, size};
  24. }
  25. #pragma Setter
  26. - (void)setCurrentDate:(BOOL)currentDate {
  27. _currentDate = currentDate;
  28. if (currentDate) {
  29. self.label.textColor = [UIColor pg_colorWithHexString:@"#FAD9A2"];
  30. }else {
  31. self.label.textColor = [UIColor pg_colorWithHexString:@"#838383"];
  32. }
  33. }
  34. - (void)setContent:(NSString *)content {
  35. _content = content;
  36. self.label.text = content;
  37. }
  38. #pragma Getter
  39. - (UILabel *)label {
  40. if (!_label) {
  41. UILabel *label = [[UILabel alloc]init];
  42. label.font = [UIFont systemFontOfSize:17];
  43. [self.contentView addSubview:label];
  44. _label = label;
  45. }
  46. return _label;
  47. }
  48. @end