JXWaitingView.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // shiku_im
  2. //
  3. // Created by flyeagleTang on 14-5-31.
  4. // Copyright (c) 2014年 Reese. All rights reserved.
  5. //
  6. #import "JXWaitingView.h"
  7. #import "UIFactory.h"
  8. @implementation JXWaitingView
  9. @synthesize isShowing;
  10. static JXWaitingView *shared;
  11. +(JXWaitingView*)sharedInstance{
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. shared=[[JXWaitingView alloc]initWithTitle:nil];
  15. });
  16. return shared;
  17. }
  18. - (id)initWithTitle:(NSString*)s
  19. {
  20. self = [super initWithFrame:g_window.bounds];
  21. if (self) {
  22. UIView* view = [[UIView alloc] initWithFrame:g_window.bounds];
  23. view.backgroundColor = [UIColor blackColor];
  24. view.alpha = 0.3;
  25. [self addSubview:view];
  26. // [view release];
  27. CGRect r = CGRectMake(60, (JX_SCREEN_HEIGHT-200)/2, 200, 200);
  28. _iv = [[UIImageView alloc]initWithFrame:r];
  29. _iv.image = [UIImage imageNamed:@"alertView-bg"];
  30. _iv.alpha = 1;
  31. [self addSubview:_iv];
  32. // [_iv release];
  33. r = CGRectMake(0, 160, _iv.frame.size.width, 20);
  34. _title = [UIFactory createLabelWith:r text:s font:nil textColor:[UIColor whiteColor] backgroundColor:[UIColor clearColor]];
  35. [_iv addSubview:_title];
  36. _title.textAlignment = NSTextAlignmentCenter;
  37. _aiv = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  38. int n = 38;
  39. _aiv.frame = CGRectMake((_iv.frame.size.width-n)/2, (_iv.frame.size.height-n)/2, n, n);
  40. [_iv addSubview:_aiv];
  41. // [_aiv release];
  42. isShowing = NO;
  43. }
  44. return self;
  45. }
  46. -(void)dealloc{
  47. // [super dealloc];
  48. }
  49. -(void)start:(NSString*)s{
  50. isShowing = YES;
  51. if(s)
  52. _title.text = s;
  53. else
  54. _title.text = Localized(@"JX_Loading");
  55. [g_window addSubview:self];
  56. self.hidden = NO;
  57. [_aiv startAnimating];
  58. }
  59. -(void)stop{
  60. isShowing = NO;
  61. [self removeFromSuperview];
  62. self.hidden = YES;
  63. [_aiv stopAnimating];
  64. }
  65. @end