UITutton在UITableViewCell中 [英] UIButton in UITableViewCell

查看:87
本文介绍了UITutton在UITableViewCell中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIButton,其中有一个UITableViewCell内的图像。当单元格突出显示时,按钮也会进入突出显示的状态(即图像的阴影颜色),无论用户是否在按钮的范围内单击。

I have a UIButton with an image inside of a UITableViewCell. When the cell is being highlight, the button is also entering the highlighted state (i.e. a darker shade of the image), regardless of whether the user is clicking within the bounds of the button or not.

我不想要这个功能 - 我只想在单击按钮时突出显示按钮,而不是在点击整个单元格时突出显示。

I don't want this functionality - I only want the button to be highlighted when the button is clicked, not when the entire cell is being clicked.

我试图将突出显示状态的图像设置为与普通图像相同。这解决了这个问题,但是当它真正突出显示时,它会阻止按钮改变颜色。

I've tried to set the image in the highlighted state to be the same as the normal image. This fixes the issue however it stops the button from changing color when it really is highlighted.

任何想法如何达到预期的效果?

Any ideas how to achieve the desired effect?

推荐答案

这让我发疯了。我想你需要覆盖 setHighlighted:animated: setSelected:animated:

This was driving me crazy. I figured out that you need to override setHighlighted:animated: and setSelected:animated:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    self.yourButton.highlighted = NO;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.yourButton.selected = NO;
    // If you don't set highlighted to NO in this method,
    // for some reason it'll be highlighed while the 
    // table cell selection animates out
    self.yourButton.highlighted = NO;
}

这篇关于UITutton在UITableViewCell中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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