/
BEMAnalogClockView.h
executable file
·264 lines (178 loc) · 11.3 KB
/
BEMAnalogClockView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
//
// BEMAnalogClockView.h
// BEMAnalogClockView
//
// Created by Boris Emorine on 2/23/14.
// Copyright (c) 2014 Boris Emorine. All rights reserved.
//
#if __has_feature(objc_modules)
// We recommend enabling Objective-C Modules in your project Build Settings for numerous benefits over regular #imports. Read more from the Modules documentation: http://clang.llvm.org/docs/Modules.html
@import Foundation;
@import UIKit;
@import CoreGraphics;
#else
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#endif
#import "KSMHand.h"
@protocol BEMAnalogClockDelegate;
/// BEMAnalogClock is an UIView subclass that gives you an easy way to create beautiful, interactive analog clocks for iOS.
@interface BEMAnalogClockView : UIView <UIGestureRecognizerDelegate>
//------------------------------------------------------------------------------------//
//----- DELEGATE ---------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// BEMAnalogClockView delegate object is essential to the clock. The delegate provides the clock with data and various parameters. The delegate can be set from the interface or from code.
@property (nonatomic, assign) IBOutlet id <BEMAnalogClockDelegate> delegate;
//------------------------------------------------------------------------------------//
//----- PROPERTIES -------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// The hours property. Used to set up the hour hand. Default value is 10.
@property (nonatomic, assign) NSInteger hours;
/// The minutes property. Used to set up the minute hand. Default value is 10.
@property (nonatomic, assign) NSInteger minutes;
/// The seconds property. Used to set up the second hand. Default value is 0.
@property (nonatomic, assign) NSInteger seconds;
/// If set to YES, the hands will cast a shadow. Default value is YES.
@property (nonatomic) BOOL enableShadows;
/// If set to YES, the graduation on the clock will be visible. See the methods bellow to costumize the graduations. Default value is YES.
@property (nonatomic) BOOL enableGraduations;
/// If set to YES, the digits (1-12) will be displayed on the face of the clock. Default value is NO.
@property (nonatomic) BOOL enableDigit;
/// If set to YES, a circular hub will be drawn. Default value is NO;
@property (nonatomic) BOOL enableHub;
/// If set to YES, the clock will be updated in real time (the second hand will move every second, the minute hand every minute...). Default value is NO;
@property (nonatomic) BOOL realTime;
/// If set to YES, the clock will be set to the current time on the phone. Prioritized over setting the time manualy. Default value is NO.
@property (nonatomic) BOOL currentTime;
/// If set to YES, the clock time can be updated via touch inputs. Default value is NO.
@property (nonatomic) BOOL setTimeViaTouch;
/// If set to YES, the clock time will suport military time. Default value is NO.
@property (nonatomic) BOOL militaryTime;
/// If set to YES, the clock real time feature is activated. Read only.
@property (readonly, nonatomic) BOOL realTimeIsActivated;
//----- CLOCK'S FACE CUSTOMIZATION -----//
/// The background color of the clock's face.
@property (strong, nonatomic) UIColor *faceBackgroundColor;
/// The alpha of the clock's face.
@property (nonatomic) CGFloat faceBackgroundAlpha;
/// The color of the clock's border.
@property (strong, nonatomic) UIColor *borderColor;
/// The alpha of the clock's border.
@property (nonatomic) CGFloat borderAlpha;
/// The width of the clock's border.
@property (nonatomic) CGFloat borderWidth;
/// The font of the digits appearing inside the clock
@property (strong, nonatomic) UIFont *digitFont;
/// The color of the digits appearing inside the clock
@property (strong, nonatomic) UIColor *digitColor;
/// The offset for the position of the digits on the clock's face. A value >0 will make the digits appear further away from the center of the clock. A valut <0 will make them closer to the center of the clock. Default value is 0.0.
@property (nonatomic) CGFloat digitOffset;
//----- HOURS HAND CUSTOMIZATION -----//
/// The color of the clock's hour hand. Default value is whiteColor.
@property (strong, nonatomic) UIColor *hourHandColor;
/// The alpha of the clock's hour hand. Default value is 1.0.
@property (nonatomic) CGFloat hourHandAlpha;
/// The width of the clock's hour hand. Default value is 4.0.
@property (nonatomic) CGFloat hourHandWidth;
/// The length of the clock's hour hand. Default value is 30.
@property (nonatomic) CGFloat hourHandLength;
/// The length of the offside part of the clock's hour hand. Default value is 10.
@property (nonatomic) CGFloat hourHandOffsideLength;
//----- MINUTES HAND CUSTOMIZATION -----//
/// The color of the clock's minute hand. Default value is whiteColor.
@property (strong, nonatomic) UIColor *minuteHandColor;
/// The alpha of the clock's minute hand. Default value is 1.0.
@property (nonatomic) CGFloat minuteHandAlpha;
/// The width of the clock's minute hand. Default value is 3.0.
@property (nonatomic) CGFloat minuteHandWidth;
/// The length of the clock's minute hand. Default value is 55.
@property (nonatomic) CGFloat minuteHandLength;
/// The length of the offside part of the clock's minute hand. Default value is 20.
@property (nonatomic) CGFloat minuteHandOffsideLength;
//----- SECONDS HAND CUSTOMIZATION -----//
/// The color of the clock's second hand. Default value is whiteColor.
@property (strong, nonatomic) UIColor *secondHandColor;
/// The alpha of the clock's second hand. Default value is 1.0.
@property (nonatomic) CGFloat secondHandAlpha;
/// The width of the clock's second hand. Default value is 1.0.
@property (nonatomic) CGFloat secondHandWidth;
/// The length of the clock's second hand. Default value is 60.
@property (nonatomic) CGFloat secondHandLength;
/// The length of the offside part of the clock's second hand. Default value is 20.
@property (nonatomic) CGFloat secondHandOffsideLength;
//----- HUB CUSTOMIZATION -----//
/// The color of the hub. Default value is whiteColor.
@property (strong, nonatomic) UIColor *hubColor;
/// The alpha of the clock's hub. Default value is 1.0.
@property (nonatomic) CGFloat hubAlpha;
/// The width of the clock's hub. Default value is 3.0.
@property (nonatomic) CGFloat hubRadius;
//------------------------------------------------------------------------------------//
//----- METHODS ----------------------------------------------------------------------//
//------------------------------------------------------------------------------------//
/// Reload the clock, all delegate methods are called again and the graph is reloaded/redrawn. Similar to calling reloadData on a UITableView.
- (void)reloadClock;
/** Update the time on the clock.
@param animated If the change of position of the hands should be animated or not. */
- (void)updateTimeAnimated:(BOOL)animated;
/** When called, this method will set the clock to the current time on the phone.
@param animated If the change of position of the hands should be animated or not. */
- (void)setClockToCurrentTimeAnimated:(BOOL)animated;
/// Start the real time feature. The clock will be updated in real time (the second hand will move every second, the minute one every minute and the hour one every hour).
- (void)startRealTime;
/// Stops the real time feature. The clock will not move anymore.
- (void)stopRealTime;
@end
@protocol BEMAnalogClockDelegate <NSObject>
@optional
//----- TIME -----//
/** The time that is currently displayed on the clock. Gets called everytime the time on the clock changes.
@param clock The clock object which is currently displaying the time.
@param hours The hours currently displayed on the clock by the hour hand.
@param minutes The minutes currently displayed on the clock by the minute hand.
@param seconds The seconds currently displayed on the clock by the second hand. */
- (void)currentTimeOnClock:(BEMAnalogClockView *)clock Hours:(NSString *)hours Minutes:(NSString *)minutes Seconds:(NSString *)seconds;
//----- DATA SOURCE -----//
/** The date format used to set up the time on the clock.
@param clock The clock object which is in need of the date format.
@return The date format string. */
- (NSString *)dateFormatterForClock:(BEMAnalogClockView *)clock;
/** The date (with time) used to set up the hands of the clock.
@param clock The clock object.
@return The date used to set up the clock. Should conform to the date formatter provided in the methode dateFormatterForClock: */
- (NSString *)timeForClock:(BEMAnalogClockView *)clock;
//----- GRADUATION CUSTOMIZATION -----//
/** The color of the graduation line at a given index. This is called for each graduation on the clock.
@param clock The clock object requesting the graduation color.
@param index The index from 0 to 59 of a given graduation. The first value for the index is 0.
@return The color of the graduation at the specific index. */
- (UIColor *)analogClock:(BEMAnalogClockView *)clock graduationColorForIndex:(NSInteger)index;
/** The alpha of the graduation line at a given index. This is called for each graduation on the clock.
@param clock The clock object requesting the graduation alpha.
@param index The index from 0 to 59 of a given graduation. The first value for the index is 0.
@return The alpha value of the graduation at the specific index. */
- (CGFloat)analogClock:(BEMAnalogClockView *)clock graduationAlphaForIndex:(NSInteger)index;
/** The width of the graduation line at a given index. This is called for each graduation on the clock.
@param clock The clock object requesting the graduation width.
@param index The index from 0 to 59 of a given graduation. The first value for the index is 0.
@return The width value of the graduation at the specific index. */
- (CGFloat)analogClock:(BEMAnalogClockView *)clock graduationWidthForIndex:(NSInteger)index;
/** The length of the graduation line at a given index. This is called for each graduation on the clock.
@param clock The clock object requesting the graduation length.
@param index The index from 0 to 59 of a given graduation. The first value for the index is 0.
@return The length value of the graduation at the specific index. */
- (CGFloat)analogClock:(BEMAnalogClockView *)clock graduationLengthForIndex:(NSInteger)index;
/** The offset of the graduation line from the border of the clock at a given index. This is called for each graduation on the clock.
@param clock The clock object requesting the graduation offset.
@param index The index from 0 to 59 of a given graduation. The first value for the index is 0.
@return The offset value from the border of the clock of the graduation at the specific index. */
- (CGFloat)analogClock:(BEMAnalogClockView *)clock graduationOffsetForIndex:(NSInteger)index;
//----- CLOCK EVENTS -----//
/** Sent to the delegate each time the clock is loaded or reloaded.
@param clock The clock object that is about to be loaded or reloaded. */
- (void)clockDidBeginLoading:(BEMAnalogClockView *)clock;
/** Sent to the delegate each time the clock finishes loading or reloading. Note that the animation is not finished at this point in time.
@param clock The clock object that finished loading or reloading. */
- (void)clockDidFinishLoading:(BEMAnalogClockView *)clock;
@end