Sommm
Sommm

Reputation: 531

Can we set image on imageview using Xcasset in Objective c?

I have imageview n view controller, whose size vary according to iphone size. I want to set height constant and width will be vary (framewidth).

So I decided to keep  differnt image in Xcassets of size 
a) (320, 110) i.e framewidth of Iphone 4s , 5s or 5c
b) (375, 110) i.e framewidth of Iphone 6 or 7
c) (414, 110) i.e framewidth of Iphone 6s or 7s

So, my question is, How to set image using XCAssets in objective c?

Upvotes: 0

Views: 609

Answers (2)

Lucas Batista Gabriel
Lucas Batista Gabriel

Reputation: 900

At your Images.xcassets you can add the same image with all the 3 images sizes and than you just use it.

To export your images, and keep all organized, export all of them with this names:

- [email protected]
- [email protected]
- [email protected]

You can check this link for more information about UIImageAsset

Now, to use those images, you don't need to care about the size, it will be pick for you according to phone size, just use the following command:

// @ your @interface
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

// @ your @implementation
[self.imageView setImage:[UIImage imageNamed:@"image-name"]];

Upvotes: 2

amit_donga
amit_donga

Reputation: 224

if you already set images in XCAssets of size 5s,4s,5c,6s,etc.. so now you want to just set only image name in your ImageView in your ViewController or where you want to set image same as XCAssets image name.

Upvotes: 1

Related Questions