button点击图标改变方法

来源:互联网 发布:统计模型的数据选择 编辑:程序博客网 时间:2024/06/06 00:06

当button被电击时button的图标会改变的状况:button按钮有两种状态设置:一种是nomal状态,一种是select状态,我们分别在这两种状态下设置自己想要的图片。然后在button的点击事件中加入,button.select=!button.select;在点击的时候button的状态就会改变,图标也会跟着改变。

//创建button设置图标

 self.selectButton=[UIButtonbuttonWithType:UIButtonTypeCustom];

    self.selectButton.frame=CGRectMake(10, 12, 22, 22);

    [self.selectButtonsetImage:[UIImageimageNamed:@"btn_multiselect_def.png"]forState:UIControlStateNormal];

    [self.selectButtonsetImage:[UIImageimageNamed:@"btn_multiselect_sel.png"]forState:UIControlStateSelected];

    [self.selectButtonaddTarget:selfaction:@selector(selectButtonClick:)forControlEvents:UIControlEventTouchUpInside];


    [selfaddSubview:self.selectButton];

//响应事件

-(void)selectButtonClick:(UIButton*)button{

    button.selected=!button.selected;

 

}



0 0
原创粉丝点击