添加动态按钮(UIAlertButton)

来源:互联网 发布:java真人面试视频 编辑:程序博客网 时间:2024/06/01 23:00

在根视图控制器类的.h文件中

#import <UIKit/UIKit.h>


@interface liViewController :UIViewController

//添加按钮

- (void) addButton;


@end

在.m文件中

@implementation liViewController


- (void)viewDidLoad

{

    [superviewDidLoad];

//调用自己的方法

    [selfaddButton];

}


- (void) addButton

{

    UIButton *button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    

    button.frame =CGRectMake(100,200, 120, 40);

    

    [button setTitle:@"点击按钮" forState:UIControlStateNormal];

    //给按钮添加关联动作

    [button addTarget:selfaction:@selector(addAlertButton:)forControlEvents:UIControlEventTouchUpInside];

    

    [self.viewaddSubview:button];

    

   // [button release];

}


- (void)addAlertButton:(id)sender

{   //添加动态按钮

   UIAlertView  *alertView = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"点击了动态按钮" delegate:nilcancelButtonTitle:@"确定" otherButtonTitles:nil,nil];

    //动态按钮的显示

    [alertViewshow];

    

    [alertViewrelease];

    

}

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


0 0
原创粉丝点击