Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,17 @@ @implementation MONViewController
- (void)viewDidLoad {
[super viewDidLoad];

MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] init];
MONActivityIndicatorView *indicatorView = [[MONActivityIndicatorView alloc] initWithParentView:self.view];
indicatorView.delegate = self;
indicatorView.numberOfCircles = 3;
indicatorView.radius = 20;
indicatorView.internalSpacing = 3;
[indicatorView startAnimating];

[self.view addSubview:indicatorView];
[self placeAtTheCenterWithView:indicatorView];


[NSTimer scheduledTimerWithTimeInterval:7 target:indicatorView selector:@selector(stopAnimating) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:9 target:indicatorView selector:@selector(startAnimating) userInfo:nil repeats:NO];
}

#pragma mark -
#pragma mark - Centering Indicator View

- (void)placeAtTheCenterWithView:(UIView *)view {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1.0f
constant:0.0f]];
}

#pragma mark -
#pragma mark - MONActivityIndicatorViewDelegate Methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
@property (weak, nonatomic) id<MONActivityIndicatorViewDelegate> delegate;


/**
Init with parent view and place activity indicator at the center of parent view
*/
- (id)initWithParentView:(UIView*) parentView;

/**
Starts the animation of the activity indicator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ - (id)initWithCoder:(NSCoder *)aDecoder {
return self;
}

- (id)initWithParentView:(UIView*) parentView {
self = [super initWithFrame:CGRectZero];
if (self) {
[self setupDefaults];
[parentView addSubview:self];
[self placeAtTheCenterOfView:parentView];
}
return self;
}

#pragma mark -
#pragma mark - Intrinsic Content Size

Expand Down Expand Up @@ -145,6 +155,27 @@ - (void)removeCircles {
}];
}

#pragma mark -
#pragma mark - Centering Indicator View

- (void)placeAtTheCenterOfView:(UIView *) parentView {
[parentView addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:parentView
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f]];

[parentView addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:parentView
attribute:NSLayoutAttributeCenterY
multiplier:1.0f
constant:0.0f]];
}

#pragma mark -
#pragma mark - Public Methods

Expand Down