创建按钮的两种方法

1、动态创建

 btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     [btnfont setFrame:CGRectMake(1001012040)];
     [btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
     [btnfont setTitle:@"字体" forState:UIControlStateNormal];
     btnfont.backgroundColor=[UIColor clearColor];
     [self.view addSubview:btnfont];
 

  

2、在xib文件中已经创建好,通过tag获取按钮 

UIButton *testButton= (UIButton*)[self.view viewWithTag:100];
    [testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];

  

注册事件

-(void) test: (id) sender{
    UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"ceshi" message:@"test11111" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
    [av show];
}

  

posted @ 2011-10-06 22:02  威风剑客  阅读(163)  评论(0编辑  收藏  举报