子曾经曰过

  博客园  :: 首页  ::  ::  ::  :: 管理

//手工添加按钮以及为按钮添加addTarget目标动作关联开始

    CGRect frame = CGRectMake(10.0f, 10.0f, 120.0f, 50.0f);

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    button.frame = frame;

    [button setTitle:@"title"forState:UIControlStateNormal];

    button.backgroundColor = [UIColorclearColor];

    button.tag = 2000//区分同种控件的标记

    [button addTarget:selfaction:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];//selector后面的方法后一定不要忘了要加个冒号 ,因为定义的buttonClicked方式后面是带了类型为id的参数

    [self.view addSubview:button];

    //手工添加按钮结束

 

-(IBAction)buttonClicked:(id)sender

{

    NSLog(@"button Clicked!");

    UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:@"title"message:@"message"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:@"otherbuttontitles", nil];

    [alert show];

    [alert release];

}

posted on 2012-05-31 15:30  人的本质是什么?  阅读(1556)  评论(0编辑  收藏  举报