1
我有一个绿色的矩形,但它不会显示当我运行该应用程序。 这里是我的代码:如何将子视图添加到视图控制器?
- (void) makeBlockg {
x = arc4random()%(320) + 1;
CGRect block = CGRectMake(x, 0, 100, 70);
greenblock.frame = block;
greenblock.self.backgroundColor = [UIColor greenColor];
[self.view addSubview:greenblock];
}
不应该是'greenblock.backgroundColor'吗? –
尝试'greenblock = [[UIView alloc] initWithFrame:block]',以及Nathan说什么 – yeesterbunny
你在哪里分配greenblock? – mayuur