I’ve been trying to set the background image of a rect button as a .png file I have on my web server. I’ve declared the button in the view controller .h and added this under .m viewdidload:
[mybutton setImage: [UIImage imageNamed: @"http://www.myserver.com/index_files/stacks_image_14.png"] forState: UIControlStateHighlighted];
but nothing shows in the button. I’ve been reading on NSSURL to see about calling in images before I try to assign them to objects, but I’m a little stuck at the moment.
Thanks for any help!
EDIT: New Code I’ve tried:
NSURL *myurl2 = [NSURL URLWithString:@"http://www.myserver.com/bigoaks.png"];
NSURLRequest *request2 = [NSURLRequest requestWithURL:myurl2
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
NSURLConnection *connection2= [[NSURLConnection alloc] initWithRequest:request2
delegate:self];
NSString *mystring2 = [NSString stringWithContentsOfURL:myurl2 encoding:NSUTF8StringEncoding error:&error];
[mybutton setImage : mystring2];
Still seem to get “No visible @interface for UIButton declares the selector ‘setImage:’
Thanks again for all the assistance!
EDIT 2:
Got it! Thanks for all of the help guys– here’s the final code to help any others:
NSURL *myurl2 = [NSURL URLWithString:@"http://www.myserver.com/bigoaks.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:myurl2]];
[mybutton setImage:image forState:UIControlStateNormal];
Using this tutorial: http://mobiledevelopertips.com/cocoa/download-and-create-an-image-from-a-url.html
Hope this is what you were looking for 🙂