如何在iOS上运行时创建控件

时间:2010-07-05 16:47:39

标签: controls ios4

有没有办法在运行时创建控件?我试过像

这样的东西
UIButton* tempButton = [[UIButton alloc] initWithFrame:CGRectMake(120, 160, 40, 40)];
[self.view insertSubview:tempButton atIndex:0];
[tempButton release];

它不起作用

1 个答案:

答案 0 :(得分:0)

UIButton* tempButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] initWithFrame:CGRectMake(120, 160, 40, 40)];
[self.view insertSubview:tempButton atIndex:0];
[tempButton release];