设置图像

迅速

button.setImage(UIImage(named:"test-image"), forState: .normal)

目标 C.

[self.button setImage:[UIImage imageNamed:@"test-image"] forState:UIControlStateNormal];

多个控制状态

你还可以为多个 UIControlStates 设置图像,例如为 SelectedHighlighted 状态设置相同的图像:

迅速

button.setImage(UIImage(named:"test-image"), forState:[.selected, .highlighted])

目标 C.

[self.button setImage:[UIImage imageNamed:@"test-image"] forState:UIControlStateSelected|UIControlStateHighlighted];