TimeBar.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // TimeBar.m
  3. // jiaPeiC
  4. //
  5. // Created by apple on 16/6/14.
  6. // Copyright © 2016年 JCZ. All rights reserved.
  7. //
  8. #import "TimeBar.h"
  9. #import "DateView.h"
  10. @implementation TimeBar
  11. -(id)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. //初始值
  16. _beginTime = @"开始时间";
  17. _endTime = @"结束时间";
  18. CGFloat x = 20;
  19. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  20. btn.frame = CGRectMake(x, 5, 80, 30);
  21. btn.backgroundColor = lineColor;
  22. [btn setTitle:@"开始时间" textColor:contentTextColor font:Font16 fotState:UIControlStateNormal];
  23. [btn borderColor:lineColor width:1 cornorRadios:5];
  24. [btn target:self Tag:1];
  25. [self addSubview:btn];
  26. beginBtn = btn;
  27. [btn addViewWithRect:CGRectMake(x + 82, 20, 16, 1)];
  28. x += 100;
  29. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  30. btn.frame = CGRectMake(x, 5, 80, 30);
  31. btn.backgroundColor = lineColor;
  32. [btn setTitle:@"结束时间" textColor:contentTextColor font:Font16 fotState:UIControlStateNormal];
  33. [btn borderColor:lineColor width:1 cornorRadios:5];
  34. [btn target:self Tag:2];
  35. [self addSubview:btn];
  36. endBtn = btn;
  37. x = frame.size.width - 46;
  38. btn = [UIButton buttonWithType:UIButtonTypeCustom];
  39. btn.frame = CGRectMake(x, 7, 26, 26);
  40. [btn setImage:[UIImage imageNamed:@"garbage.png"] forState:UIControlStateNormal];
  41. [btn target:self Tag:3];
  42. [self addSubview:btn];
  43. }
  44. return self;
  45. }
  46. -(void)showWithRemove:(MyBlockType)remove
  47. {
  48. removeBlock = remove;
  49. }
  50. -(void)finishEndTime:(MyBlockType)endTimeB
  51. {
  52. endTimeBlock = endTimeB;
  53. }
  54. -(void)btnClick:(UIButton *)sender
  55. {
  56. if (sender.tag == 3) {
  57. if (removeBlock) {
  58. removeBlock(_timeTag);
  59. }
  60. return;
  61. }
  62. DateView* dv = [[DateView alloc] init];
  63. [dv setStyle:1];
  64. [dv showWithComplete:^(NSString *time) {
  65. if (sender.tag == 1) {
  66. _beginTime = time;
  67. [beginBtn setTitle:time forState:UIControlStateNormal];
  68. }
  69. if (sender.tag == 2) {
  70. _endTime = time;
  71. [endBtn setTitle:time forState:UIControlStateNormal];
  72. if (endTimeBlock) {
  73. endTimeBlock(_timeTag);
  74. }
  75. }
  76. }];
  77. }
  78. -(void)setBeginAndEndTimeWithBeginTime:(NSString *)beginString EndTime:(NSString *)endString
  79. {
  80. _beginTime = beginString;
  81. _endTime = endString;
  82. [beginBtn setTitle:beginString forState:UIControlStateNormal];
  83. [endBtn setTitle:endString forState:UIControlStateNormal];
  84. }
  85. @end