语境
- 这是堆栈
UIViewController中的一个UINavigationController - 在此
UIViewController我以UILabel编程方式在 (0,0) 的 (x,y) 坐标处添加一个 - 我已经尝试添加
UILabel到 self.view (这是在 UIViewController 中)或添加UILabel到 aUIView,这UIView是 self.containerView
self.containerView通过以下代码创建并添加到视图中:
- (void)addContainerView
{
// Create a UIView with same frame as the screen bounds
CGRect containerViewFrame = [[UIScreen mainScreen] applicationFrame];
self.containerView = [[UIView alloc] initWithFrame:containerViewFrame];
// Give the UIView a red background
self.containerView.backgroundColor = [UIColor redColor];
// Add the view
[self.view addSubview:self.containerView];
}
通过以下UILabel代码添加:
- (void)addTestLabel
{
self.navigationController.navigationBarHidden = YES;
CGRect frame = CGRectMake(0, 0, 100, 100);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text = @"this is a test";
[self.view addSubview:label]; // OR [self.containerView addSubview:label]
}

何时UILabel添加到self.view

何时UILabel添加到self.containerView
问题
- 为什么不在
UILabel屏幕顶部,甚至在状态栏后面? - 为什么有区别
yPos,取决于它是添加到self.view还是self.containerView