UIButton:currentImage 属性
currentImage 属性是按钮此刻显示的图标,也就是按当前状态选出来的那一个。
值
UIImage,或者 null。
- 只读。给它赋值抛
TypeError。 - 当前状态没有单独设过时,读出的是
normal状态的那一个。 - 没有变化通知。它跟着按钮的状态变:手指按下和松开(系统派发
touchdown、touchupinside这类控件事件),或者代码改了isEnabled、isSelected。状态本身没有变化事件,所以要在这些时机重新读。 - 任何状态都没设过图标时是
null。未在模拟器验证。
示例
js
const button = UIButton.buttonWithType('system');
button.setImage(UIImage.systemImageNamed('heart'), { forState: ['normal'] });
console.log(button.currentImage !== null);结果:输出 true。未在模拟器验证。
对应的 iOS API
UIButton.currentImage。
参见
- 状态:按钮什么时候处于哪个状态