0

我正在尝试在当前视图上添加 UIView,但没有运气.. 我确定我的代码是正确的,但不确定还要检查什么,插入子视图时我还应该考虑什么

这就是我添加到 viewDidLoad 中的内容

//..
    cellContainer = [[UIView alloc] init];

    cellContainer.frame = CGRectMake(0.0, 480.0, 320.0, 300.0);

    [self.view addSubview:cellContainer];

    self.view.backgroundColor = [UIColor greenColor];
//..

cellContainer 在标题中声明为 UIView ......任何帮助将不胜感激。

4

1 回答 1

4

cellContainer可能会添加到 的视图层次结构中UIViewController,但您已将框架设置为不在屏幕上。试试这个:

 cellContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
 [self.view addSubview:cellContainer];
 self.view.backgroundColor = [UIColor greenColor];

这将显示cellContainer在视图的左上角,在右 x 方向上延伸 320 像素,在下 y 方向上延伸 300 像素。

于 2012-08-22T03:00:21.073 回答