MZTimerLabel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // MZTimerLabel.h
  3. // Version 0.2
  4. // Created by MineS Chan on 2013-10-16
  5. // Updated 2013-11-05
  6. // This code is distributed under the terms and conditions of the MIT license.
  7. // Copyright (c) 2013 MineS Chan
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. #import <UIKit/UIKit.h>
  27. /**********************************************
  28. MZTimerLabel TimerType Enum
  29. **********************************************/
  30. typedef enum{
  31. MZTimerLabelTypeStopWatch,
  32. MZTimerLabelTypeTimer
  33. }MZTimerLabelType;
  34. /**********************************************
  35. Delegate Methods
  36. @optional
  37. - timerLabel:finshedCountDownTimerWithTimeWithTime:
  38. ** MZTimerLabel Delegate method for finish of countdown timer
  39. - timerLabelCountingTo:timertype:
  40. ** MZTimerLabel Delegate method for monitering the current counting progress
  41. **********************************************/
  42. @class MZTimerLabel;
  43. @protocol MZTimerLabelDelegate <NSObject>
  44. @optional
  45. -(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime;
  46. -(void)timerLabel:(MZTimerLabel*)timerlabel countingTo:(NSTimeInterval)time timertype:(MZTimerLabelType)timerType;
  47. @end
  48. /**********************************************
  49. MZTimerLabel Class Defination
  50. **********************************************/
  51. @interface MZTimerLabel : UILabel{
  52. #if NS_BLOCKS_AVAILABLE
  53. void (^endedBlock)(NSTimeInterval);
  54. #endif
  55. NSTimeInterval timeUserValue;
  56. NSDate *startCountDate;
  57. NSDate *pausedTime;
  58. NSDate *date1970;
  59. NSDate *timeToCountOff;
  60. }
  61. /*Delegate for finish of countdown timer */
  62. @property (strong) id<MZTimerLabelDelegate> delegate;
  63. /*Time format wish to display in label*/
  64. @property (nonatomic,strong) NSString *timeFormat;
  65. /*Target label obejct, default self if you do not initWithLabel nor set*/
  66. @property (strong) UILabel *timeLabel;
  67. /*Type to choose from stopwatch or timer*/
  68. @property (assign) MZTimerLabelType timerType;
  69. /*is The Timer Running?*/
  70. @property (assign,readonly) BOOL counting;
  71. /*do you reset the Timer after countdown?*/
  72. @property (assign) BOOL resetTimerAfterFinish;
  73. /*--------Init method to choose*/
  74. -(id)initWithTimerType:(MZTimerLabelType)theType;
  75. -(id)initWithLabel:(UILabel*)theLabel andTimerType:(MZTimerLabelType)theType;
  76. -(id)initWithLabel:(UILabel*)theLabel;
  77. /*--------Timer control method to use*/
  78. -(void)start;
  79. #if NS_BLOCKS_AVAILABLE
  80. -(void)startWithEndingBlock:(void(^)(NSTimeInterval countTime))end; //use it if you are not going to use delegate
  81. #endif
  82. -(void)pause;
  83. -(void)reset;
  84. /*--------Setter methods*/
  85. -(void)setCountDownTime:(NSTimeInterval)time;
  86. -(void)setStopWatchTime:(NSTimeInterval)time;
  87. @end