Looking for ios Answers? Try Ask4KnowledgeBase
Looking for ios Keywords? Try Ask4Keywords

iOS Set Image


Example

Swift

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

Objective C

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

Multiple Control States

You can also set an image for multiple UIControlStates, for example to set the same image for the Selected and Highlighted state:

Swift

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

Objective C

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