Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7735995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:38:23+00:00 2026-06-01T07:38:23+00:00

I am trying to do download some images from server then , set these

  • 0

I am trying to do download some images from server then , set these images as background image for some UIButtons .

so first downloading images :

NSString *urlMag1 = [NSString stringWithFormat:@"http://myweb.com/i224_mag1.png"];
    NSString *urlMag2 = [NSString stringWithFormat:@"http://myweb.com/i224_mag2.png"];
    NSString *str = [NSString stringWithFormat:urlMag1,urlMag2,nil];

    NSData *data = [NSData dataWithContentsOfFile:str];
    NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    [data writeToFile:path atomically:YES];

    UIImage *imgMag1 = [UIImage imageNamed:@"i224_mag2.png"];
    [mag2 setBackgroundImage:imgMag1 forState:UIControlStateNormal];

but nothing happens !!,and how can I check to if these images are in directory to avoid more downloading

I would be grateful if you help me to solve this

thanks !

EDITED
@Fernando Cervantes

I created a method to set buttons BG images something like this , but I don’t know why does not work !

- (UIImage *)loadImages :(NSString *)fileNames ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {

    [[NSFileManager defaultManager] fileExistsAtPath:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", fileNames, extension]]];
    return 0;
}

and set BG images :

- (void)buttonsBGImage {



    UIImage * bgMag2 = [self loadImages:@"i224_mag2" ofType:@"png" inDirectory:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];

    [mag2 setBackgroundImage:bgMag2 forState:UIControlStateNormal];


}

but actually nothing happens ! even I check the file and it’s in app directory

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:38:25+00:00Added an answer on June 1, 2026 at 7:38 am

    The following approach might help you out a bit.

    Save

    -(void) saveFile:(NSString *)fileName ofType:(NSString *)extension fromURL:(NSString *)fileIndexPath inDirectory:(NSString *)directoryPath {
        NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileIndexPath]];
    
        [data writeToFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension] atomically:YES];
    }
    

    Check

    -(BOOL) checkIfFileExists:(NSString *)fileName ofType:(NSString *)extension inDirectoryPath:(NSString *)directoryPath {
        bool result;
    
        if ([[NSFileManager defaultManager] fileExistsAtPath:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", fileName, extension]]]) {
            result = TRUE;
        } else {
            result = FALSE;
        }
    
        return result;
    }
    

    Set

    UIButton * button = [[UIButton alloc] init];
    UIImage * backgroundImage = [self loadImage:@"YourImageName" ofType:@"png" inDirectory:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]];
    
    [button setImage:backgroundImage forState:UIControlStateNormal];
    

    -Edited-

    I believe your problem is that you are returning 0 in your loadImages method. Instead of returning the image itself.

    This is how I accomplished it:

    Load

    -(UIImage *) loadImage:(NSString *)fileName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath {
    
        UIImage * result = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.%@", directoryPath, fileName, extension]];
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to download 16-bit image data from a server and push it into
im trying to asyncronously download some images in an asynctask and then in the
I'm trying to download images (.jpg) from web folder using wget. I want to
I'm trying to download images from URLs and pass them to PIL. I would
I am trying to download the image from the url http://a3.twimg.com/profile_images/414797877/05052008321_bigger.jpg I am using
All I need to do is download some basic text-based and image files from
i am trying to load images from facebook. if a user has set a
What I'm trying to do is download a set of images, about 200 of
I'm trying to download imags from a url and then decode them. The problem
I'm trying to download some data using pure javascript/html from cross-domain, dropbox to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.