Skip to content

UIButton:backgroundImageForState() 方法 ​

backgroundImageForState() 方法返回按钮在某个状态下使用的背景图。

语法 ​

backgroundImageForState(state)

参数 ​

state

一个状态名,字符串:'normal'、'highlighted'、'disabled'、'selected'、'focused' 之一。

和设置的方法不同,这里只能传一个状态名,不能传数组。

返回值 ​

UIImage,或者 null。返回的是设进去的同一个对象。

这个状态没有单独设过时,返回 normal 状态的那一个。normal 也没设过时返回 null。

异常 ​

TypeError

state 不是上面的状态名之一。

示例 ​

js
const button = new UIButton();
console.log(button.backgroundImageForState('normal'));

结果:输出 null。未在模拟器验证。

对应的 iOS API ​

-[UIButton backgroundImageForState:]。

参见 ​