首页 > 代码库 > 代码创建button、view、label等控件

代码创建button、view、label等控件

UIButton *b1=[[UIButton alloc]initWithFrame:CGRectMake(200, 200, 40, 20)];

    b1.backgroundColor=[UIColor redColor];

    view1=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];

    view1.backgroundColor=[UIColor grayColor];

    [self.view addSubview:view1];

    [self.view addSubview:b1];

    [b1 addTarget:self action:@selector(b1click:) forControlEvents:UIControlEventTouchUpInside];

    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 375, 17)];

    label.backgroundColor=[UIColor yellowColor];

    [self.view addSubview:label];

代码创建button、view、label等控件