CalenderWeekView.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // CalenderWeekView.m
  3. // YZCCalender
  4. //
  5. // Created by Jason on 2018/1/17.
  6. // Copyright © 2018年 jason. All rights reserved.
  7. //
  8. #import "CalenderWeekView.h"
  9. #import "UIColor+Extension.h"
  10. @interface CalenderWeekView ()
  11. @property (nonatomic, strong) UIView *lineView;
  12. @end
  13. @implementation CalenderWeekView
  14. - (void)setDataSource:(NSArray *)dataSource {
  15. _dataSource = dataSource;
  16. for (UIView *view in self.subviews) {
  17. if ([view.class isKindOfClass:UILabel.class]) {
  18. [view removeFromSuperview];
  19. }
  20. }
  21. CGFloat count = dataSource.count;
  22. CGFloat labelW = self.frame.size.width / count;
  23. CGFloat labelY = 0;
  24. CGFloat labelH = self.frame.size.height;
  25. for (int i = 0; i < count; i++) {
  26. CGFloat labelX = i * labelW;
  27. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(labelX, labelY, labelW, labelH)];
  28. label.textAlignment = NSTextAlignmentCenter;
  29. label.textColor = [UIColor colorWithHexString:@"#666666"];
  30. label.font = [UIFont systemFontOfSize:11];
  31. label.text = dataSource[i];
  32. [self addSubview:label];
  33. }
  34. }
  35. - (UIView *)lineView {
  36. if (_lineView == nil) {
  37. _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, self.frame.size.width, 1)];
  38. _lineView.backgroundColor = self.weekBottomLineColor ? self.weekBottomLineColor : [UIColor lightGrayColor];
  39. }
  40. return _lineView;
  41. }
  42. -(void)setWeekBottomLineColor:(UIColor *)weekBottomLineColor {
  43. _weekBottomLineColor = weekBottomLineColor;
  44. self.lineView.backgroundColor = self.weekBottomLineColor ? self.weekBottomLineColor : [UIColor colorWithHexString:@"#000000" alpha:0.1];
  45. }
  46. - (void)setShowLine:(BOOL)showLine {
  47. _showLine = showLine;
  48. if (showLine) {
  49. [self addSubview:self.lineView];
  50. } else {
  51. [self.lineView removeFromSuperview];
  52. }
  53. }
  54. @end