首页 > 代码库 > ios动态创建UIView

ios动态创建UIView

- (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.
}