2011-08-15 36 views
0

我有一個UISplitViewController,並試圖在右視圖控制器中居中(水平和垂直)一個UILabel。當它以縱向加載時,標籤看起來是正確的,但如果將其旋轉到橫向,則標籤不再垂直居中。我正在使用:iOS:UILabel以視圖爲中心

CGSize size = self.view.frame.size; 
UILabel *noResults = [[UILabel alloc] initWithFrame:CGRectMake(0, 40.0f, size.width, size.height)]; 
noResults.text = @"No people were found."; 
noResults.textColor = [UIColor blackColor]; 
noResults.textAlignment = UITextAlignmentCenter; 
noResults.backgroundColor = [UIColor clearColor]; 
noResults.textColor = [UIColor darkGrayColor]; 
noResults.font = [UIFont systemFontOfSize:16.0]; 
noResults.shadowColor = [UIColor whiteColor]; 
noResults.shadowOffset = CGSizeMake(0, 1); 
noResults.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
self.noResultsLabel = noResults; 
[self.view addSubview:noResultsLabel]; 
[noResults release]; 

我以爲它會自動調整自己的大小,當我使用autoresize掩碼?

回答

1

你還應該指定的利潤率是靈活的,這樣的:

noResults.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 

通過使用此代碼,您將得到重新定位水平的按鈕。如果您還希望將其垂直重新定位,請指定UIViewAutoresizingFlexibleTopMarginUIViewAutoresizingFlexibleBottomMargin

+0

完美!它像我需要的那樣工作,謝謝! –