AhMaD AbUIeSa
AhMaD AbUIeSa

Reputation: 815

how can I include resources in native ios codename one?

how can I include some pictures for the native ios [ in codename one ] and how can I use them from inside the code , I tried to create a folder Called Resources like what XCode do by default , and it didn't work code used :

[UIImage imageNamed:@"xxxx.png"];

Regards,

after trying to include the sources I looked everywhere for the images and I didn't find any [ tried to put them inside the src and inside native and inside ios folder ]

after trying to work with gui from native I have the following messages on the log : 2017-03-16 15:23:25.509 MyApplication[32748:1247180] Warning: Attempt to present on whose view is not in the window hierarchy!

Upvotes: 2

Views: 113

Answers (2)

Diamond
Diamond

Reputation: 7483

If you want to bundle images with your Codename One App, there are at least 2 ways of doing that:

1:

Add the images to the src folder in your project and get them as follows:

public static Image getImageFromSrcFolder(String imageName) {
    try {
        Image image = Image.createImage(Display.getInstance().getResourceAsStream(null, imageName));
        return image;
    } catch (IOException ioe) {
        //Log.p("Image " + name + " not found: " + ioe);
    }
    return null;
}

2:

Add the images through the GUI Builder (theme.res) and get them as follows:

public static Image getImageFromTheme(String imageName) {
    try {
        Resources resFile = Resources.openLayered("/theme");//Change 'theme' to the custom name, if you renamed your theme.res file
        Image image = resFile.getImage(imageName);
        return image;
    } catch (IOException ioe) {
        //Log.p("Image " + name + " not found: " + ioe);
    }
    return null;
}

Upvotes: 2

Abhishek Mitra
Abhishek Mitra

Reputation: 3395

You have to use Like

UIImageView *yourImageView; // this must be your IBOutlet imageview, else you have to allocate it manually by giving its size frame etc.
[yourImageView setImage:[UIImage imageNamed:@"xxx.png"]];

Try this, it will work. Thanks.

Upvotes: 1

Related Questions