以下实现创建和销毁View,以及创建和销毁按钮的代码,希望对iPhone App开发新手有所帮助。
创建 myView:
UIVIew *myView = [[UIView alloc] initWithFrame:CGRectMaker(0,0,100,100)];
[anyView
addSubview:myView];
[myView release];
销毁myView;
[myView removeFromSuperview];
在view中创建button:
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
btn.frame = CGRectMake(60,60, 60, 60);
[self.view addSubview:btn];
在view中销 毁button:
[btn removeFromSuperview];
[btn release];
创建 myView:
UIVIew *myView = [[UIView alloc] initWithFrame:CGRectMaker(0,0,100,100)];
[anyView
[myView release];
销毁myView;
[myView removeFromSuperview];
在view中创建button:
UIButton *btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
btn.frame = CGRectMake(60,60, 60, 60);
[self.view addSubview:btn];
在view中销 毁button:
[btn removeFromSuperview];
[btn release];