我試圖在加載表視圖時顯示一個動畫微調框。在視圖控制器的中心居中視圖
loadingView = [[UIView alloc] initWithFrame:CGRectMake(75, 155, 170, 170)];
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
loadingView.clipsToBounds = YES;
loadingView.layer.cornerRadius = 10.0;
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.frame = CGRectMake(65, 40, activityView.bounds.size.width, activityView.bounds.size.height);
[loadingView addSubview:activityView];
loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
loadingLabel.backgroundColor = [UIColor clearColor];
loadingLabel.textColor = [UIColor whiteColor];
loadingLabel.adjustsFontSizeToFitWidth = YES;
loadingLabel.textAlignment = NSTextAlignmentCenter;
loadingLabel.text = @"Loading...";
[loadingView addSubview:loadingLabel];
[self.view addSubview:loadingView];
[activityView startAnimating];
我已經嵌入loadingView
一個UIActivityIndicatorView
。 我面臨的問題是:
- 加載視圖不在視圖控制器的中心。
- 我試圖將加載視圖居中視圖控制器的中心,
UIActivityIndicatorView
必須在加載視圖的中心,但它沒有像我期待的那樣居中。
你爲什麼要硬編碼任何CGRect值?大多數應該根據每個視圖的父視圖的大小來計算。 – rmaddy