我在将标签定位在视图顶部时遇到了一些麻烦,以便它居中。但是,当我使用日期时,字符串的宽度会有所不同。我还注意到在 3.5 英寸的屏幕上,文本不适合。标签的两侧还有两个图像按钮。
所以我需要有一个保证金。
更复杂的是,视图仅以横向显示,因此左侧是顶部等。
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];