我在定位視圖頂部的標籤時遇到了一些麻煩,因此它居中。但是,由於我使用日期,字符串的寬度會有所不同。我也注意到,在3.5英寸的屏幕上,文字不適合。我在標籤的兩側也有兩個圖像按鈕。Obj-C,頂部居中視圖上的標籤/
所以我需要一個保證金。
更爲複雜的是,該視圖只顯示景觀,所以左邊是頂等
ViewController *nextController = [[ViewController alloc]
initWithNibName:@"View" bundle:nil];
CGAffineTransform newTransform = CGAffineTransformMake(0.0,1.0,-1.0,0.0,0.0,0.0);
nextController.view.transform = newTransform;
nextController.hidesBottomBarWhenPushed = YES;
我想所有我需要做的是......
int margin = 50;
lblTitle.frame = CGRectMake(margin, 2, th - (margin * 2), 22);
但這並不奏效。 這幾乎就像在左邊添加狀態欄的高度,但狀態欄是可見的。我做了很多次嘗試,不知道我做錯了什麼。
lblTitle = [[UILabel alloc] initWithFrame:CGRectZero];
lblTitle.text = [NSString stringWithFormat:@"%@ - from %@ to %@",
strChartType, displayStartDate, displayEndDate];
int th = self.view.frame.size.height;
//int th = self.view.bounds.size.height;
lblTitle.frame = CGRectMake(0, 2, th, 22); // x, y, w, h
//[lblTitle setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin];
//lblTitle.center = CGPointMake(self.view.bounds.size.width/2, 10);
[lblTitle setTextAlignment:UITextAlignmentCenter];
lblTitle.font = [UIFont boldSystemFontOfSize:14];
lblTitle.adjustsFontSizeToFitWidth = FALSE;
lblTitle.backgroundColor = [UIColor yellowColor];
[self.view addSubview:lblTitle];
'CGRectGetMidX()'和'CGRectGetMidY()'應該是有幫助的 –
什麼是評估對象,你認爲它應該是什麼? – Joel