Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 979
p0lAris Avatar asked Oct 16 '14 00:10

p0lAris


1 Answers

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");
like image 65
Dan Harms Avatar answered Oct 22 '22 23:10

Dan Harms