UIButton in UITableViewCell(UITableViewCell 中的 UIButton)
问题描述
我在 UITableViewCell 中有一个带有图像的 UIButton.当单元格被突出显示时,按钮也进入突出显示状态(即图像的较暗阴影),无论用户是否在按钮的范围内单击.
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;
}
这篇关于UITableViewCell 中的 UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UITableViewCell 中的 UIButton


基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01