1、动态创建
1 btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
2 [btnfont setFrame:CGRectMake( 100, 10, 120, 40)];
3 [btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
4 [btnfont setTitle: @" 字体 " forState:UIControlStateNormal];
5 btnfont.backgroundColor=[UIColor clearColor];
6 [self.view addSubview:btnfont];
7
2 [btnfont setFrame:CGRectMake( 100, 10, 120, 40)];
3 [btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
4 [btnfont setTitle: @" 字体 " forState:UIControlStateNormal];
5 btnfont.backgroundColor=[UIColor clearColor];
6 [self.view addSubview:btnfont];
7
8
2、在xib文件中已经创建好,通过tag获取按钮
UIButton *testButton= (UIButton*)[self.view viewWithTag:
100];
[testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[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];
}
UIAlertView *av = [[[UIAlertView alloc] initWithTitle: @" ceshi " message: @" test11111 " delegate:nil cancelButtonTitle: @" OK "otherButtonTitles:nil] autorelease];
[av show];
}