1

I have these two views that i would like to align to be centered.

self.loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 120, 120)];
self.loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
self.loadingView.clipsToBounds = YES;
self.loadingView.layer.cornerRadius = 10.0;

self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.activityView.frame = CGRectMake(65, 40, self.activityView.bounds.size.width, self.activityView.bounds.size.height);

[self.loadingView addSubview:self.activityView];

loadingView needs to be aligned center to the iPhones screen. This means a code that can support different sizes of screens. And then activityView should be aligned centered inside the loadingView.

I have tried some code examples but none worked. And it was really confusing. If someone could provide some code exampels and explaing a bit how it works to get a hang of this.

EDIT1

enter image description here

I wrote just as you did i added the self.view.center part but it is still not in the middle?

Also the second question was how to add the indicator view in the CENTER of the loadingView.

1 Answers1

1
- (void)viewDidLoad {
    [super viewDidLoad];


    self.view.backgroundColor= [UIColor blackColor];
    UIActivityIndicatorView * indicator;

            indicator = [[UIActivityIndicatorView alloc] init];
            indicator.center = self.view.center;
            indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
            [indicator startAnimating];
            [self.view addSubview:indicator];

    // Do any additional setup after loading the view, typically from a nib.
} 

iphone 6
this will add the activity indicator in the center of the screen..

Majid Bashir
  • 558
  • 1
  • 4
  • 27