Tuesday, 17 September 2013

Spinner (UIActivityIndicatorView) at the Center of View with AutoLayout



UIActivityIndicatorView  *spinner;
spinner =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setTranslatesAutoresizingMaskIntoConstraints:NO];
spinner.color=[UIColor blackColor];
    [self.view addSubview:spinner];

 NSLayoutConstraint *cont = [NSLayoutConstraint constraintWithItem:spinner attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0];
    [self.view addConstraint:cont];

 cont = [NSLayoutConstraint constraintWithItem:spinner attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0];

    [self.view addConstraint:cont];

.
.
.
.
.
 [spinner startAnimating];
.
.
.
.
.
 [spinner stopAnimating];

No comments:

Post a Comment