- (id)initWithFrame:(CGRect)frame; // default initializer
// (CGRect)frame:UIView的大小
创建一个UIView
- (void)viewDidLoad
{
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(10, 50, 300, 200)]; // 初始化一个UIView
[v setBackgroundColor:[UIColor redColor]]; // 设置背景颜色
[self.view addSubview:v]; // 将创建的视图添加到当前视图中
// [UIButton][super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
ios动态创建UIView
时间: 2024-10-01 07:01:52