Ios 如何对齐视图和子视图中心目标-C

Ios 如何对齐视图和子视图中心目标-C,ios,objective-c,iphone,alignment,cgrectmake,Ios,Objective C,Iphone,Alignment,Cgrectmake,我有这两个视图,我想对齐以居中 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.corner

我有这两个视图,我想对齐以居中

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需要与iPhone屏幕的中心对齐。这意味着代码可以支持不同大小的屏幕。然后activityView应该在loadingView中居中对齐

- (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.
} 
我尝试了一些代码示例,但都没有成功。这真的让人困惑。如果有人能提供一些代码示例,并解释一下它是如何工作的,以了解这一点

EDIT1

我写的和你一样,我添加了Self.VIEW.CHINA部分,但是它还没有在中间?

第二个问题是如何在loadingView的中心添加指示器视图

- (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.
} 


这将在屏幕中央添加活动指示器。

如何创建默认属性?。我不能只写self.center,当我这样做时,它找不到任何东西?它的self.view.center检查我的问题,它用图片@magid更新