drc*_*drc 0 uiview uilabel ios
上下文
UIViewController一个UINavigationController堆栈内的UIViewController我UILabel在(x,y)坐标(0,0)处以编程方式添加UILabel到self.view(这是在UIViewController中)或添加UILabel到a UIView,这UIView是self.containerViewself.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];
}
Run Code Online (Sandbox Code Playgroud)
将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]
}
Run Code Online (Sandbox Code Playgroud)

何时UILabel加入self.view

何时UILabel加入self.containerView
问题
UILabel坐在屏幕顶部,即使在状态栏后面?yPos,取决于它是否被添加到self.view或self.containerView | 归档时间: |
|
| 查看次数: |
351 次 |
| 最近记录: |