p0lAris
p0lAris

Reputation: 4820

Specify asset image for UIImageView for all devices

Is there a way I can say for a particular UIImageView:

UIImageView *imageView = <#instantiate#>
imageView.image = @"someImageFromImageAsset";

and based on the device it's rendering on, it sets the right image. Obviously I need to set the image for a particular device but I am unsure how you do it.

Upvotes: 8

Views: 8947

Answers (1)

Dan Harms
Dan Harms

Reputation: 4840

iOS will automatically choose the correct sized image if you just use the name of the image. Use @2x in the image file name for retina display.

Objective-C

imageView.image = [UIImage imageNamed: @"someImageName"];

Swift

imageView.image = UIImage(named: "someImageName");

Upvotes: 16

Related Questions