代码创建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];

posted on 2014-10-09 21:15  陈丰波  阅读(268)  评论(0编辑  收藏  举报