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掩碼?
完美!它像我需要的那樣工作,謝謝! –