WaitingView.m 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // WaitingView.m
  3. // NoteLedge for Mac
  4. //
  5. // Created by kdanmobile on 14-3-31.
  6. // Copyright (c) 2014年 kdanmobile. All rights reserved.
  7. //
  8. #import "WaitingView.h"
  9. @implementation NSView (Centering)
  10. - (void) center {
  11. if (![self superview]) return;
  12. [self setFrame:NSMakeRect(
  13. 0.5 * ([self superview].frame.size.width - self.frame.size.width),
  14. 0.5 * ([self superview].frame.size.height - self.frame.size.height),
  15. self.frame.size.width,
  16. self.frame.size.height
  17. )];
  18. }
  19. @end
  20. @implementation WaitingView
  21. - (id)initWithFrame:(NSRect)frame
  22. {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. _indicator = [[NSProgressIndicator alloc] init];
  26. [_indicator setBezeled:NO];
  27. [_indicator setAutoresizingMask:63];
  28. [_indicator setStyle:NSProgressIndicatorSpinningStyle];
  29. [_indicator setControlSize:NSRegularControlSize];
  30. [_indicator setUsesThreadedAnimation:YES];
  31. [_indicator sizeToFit];
  32. [self addSubview:_indicator];
  33. [_indicator center];
  34. }
  35. return self;
  36. }
  37. - (void)startAnimation
  38. {
  39. [_indicator startAnimation:nil];
  40. }
  41. - (void)drawRect:(NSRect)dirtyRect
  42. {
  43. [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:0.5] set];
  44. [NSBezierPath fillRect:self.bounds];
  45. }
  46. - (void)mouseDown:(NSEvent *)theEvent
  47. {
  48. }
  49. - (void)mouseUp:(NSEvent *)theEvent
  50. {
  51. }
  52. @end