button.setImage(UIImage(named:"test-image"), forState: .normal)
[self.button setImage:[UIImage imageNamed:@"test-image"] forState:UIControlStateNormal];
You can also set an image for multiple UIControlStates
, for example to set the same image for the Selected
and Highlighted
state:
button.setImage(UIImage(named:"test-image"), forState:[.selected, .highlighted])
[self.button setImage:[UIImage imageNamed:@"test-image"] forState:UIControlStateSelected|UIControlStateHighlighted];