如何根据(id)sender获取UIButton的信息

来源:互联网 发布:ubuntu安装分区方案 编辑:程序博客网 时间:2024/05/03 07:34

-(IBAction) buttonClick:(id)sender   //sender参数,表示接受哪个按钮消息

{

    UIButton *button = (UIButton *)sender;  //参数id是一个通用内型,此处将其强制转换成UIButton内型

    //每个button都有唯一的tag,系统默认陪标示用的,是一个整数

    NSString *title =[NSString stringWithFormat:@"Button tag %d",button.tag];//将button tag 转换成字符串输出

     NSString *mesage = [button currentTitle];     //取得button名称

}

网上搜的,记录一下