- <span style="font-size:14px;">
- #import "ViewController.h" @interface ViewController () @property(strong,nonatomic)
- UIButton *button; @end @implementation ViewController - (void)viewDidLoad
- { [super viewDidLoad]; self.button = [[UIButton alloc] initWithFrame:CGRectMake(0,
- 100, [[UIScreen mainScreen] bounds].size.width, 20)]; [self.button setTitle:@"跳转"
- forState:UIControlStateNormal]; [self.button setTitleColor:[UIColor blackColor]
- forState:UIControlStateNormal]; [self.view addSubview:self.button]; [self.button
- addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
- } -(void)clickMe:(id)sender{ UIAlertView *alert = [[UIAlertView alloc]
- initWithTitle:@"提示" message:@"按钮被点击了" delegate:self cancelButtonTitle:@"确定"
- otherButtonTitles:nil, nil]; [alert show]; } @end
- </span>
来源: http://lib.csdn.net/snippet/ios/43462