UIButton状态已选择 [英] UIButton state selected

查看:120
本文介绍了UIButton状态已选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多有关更改所选按钮图像的信息,但是作为新手,实现它的简单版本会遇到一些麻烦.

I've seen a lot of info on changing the button image for selected but being a new I'm having a bit of trouble implementing a simpler version of it.

当按下按钮时,它会变黑,我希望它在被选择后保持这种状态.所以有几个问题.

When the button is pressed it goes dark and I would like it to stay that way once it's been selected. So there are a few questions.

我是否为按钮创建IBOutlet,然后创建IBAction以使用button.state = SELECTED之类的方式更改状态.

Do I create IBOutlet for the button and then and IBAction to change the state with something like button.state = SELECTED.

很抱歉,我们完全找不到任何代码.

Sorry for the complete lack of any code to look at.

(id)发送者是按钮对象吗?

(id)sender is the button object right?

-(IBAction)journalEntryViewControllerClick: (id)sender
{
    UIButton *button = (id)sender;

    [button setSelected:YES];   

}

推荐答案

您可以为按钮的选定状态(UIControlStateSelected)设置单独的图像,并且在按钮操作中可以切换其状态:

You can set separate image for button's selected state (UIControlStateSelected) and in button action you can toggle its state:

- (void) btnAction:(UIButton*)button{
    button.selected = !button.selected;
}

这篇关于UIButton状态已选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆