Reputation: 19303
I've been using this code and it's working fine:
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: currentMovie.trailerThumb]];
[button setBackgroundImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
[_moviesScroll addSubview:button];
Now I'm trying to load the pictures using AFNetworking like this:
UIImageView *testMe = [[UIImageView alloc]init];
[testMe setImageWithURL:[NSURL URLWithString:currentMovie.trailerThumb] placeholderImage:[UIImage imageNamed:@"placeHolder.png"]];
[button setBackgroundImage:testMe.image forState:UIControlStateNormal];
[_moviesScroll addSubview:button];
I get the place holder image fine but the original picture won't show.
I tried doing something like this: I connected an outlet to an imageView in the IB and added this code:
[_test setImageWithURL:[NSURL URLWithString:@"https://www.url.com/pic.png"] placeholderImage:[UIImage imageNamed:@"placeHolder.png"]];
The image will show fine. But if i'll do this:
[button setBackgroundImage:_test.image forState:UIControlStateNormal];
Again, just the place holder will show.
Upvotes: 1
Views: 813
Reputation: 19303
I ended up using a commit one of the users added here. With that commit it's simple as
[button setImageWithURL:[NSURL URLWithString: currentMovie.trailerThumb] placeholderImage:[UIImage imageNamed:@"placeHolder.png"] forState:UIControlStateNormal];
Upvotes: 1
Reputation: 1017
try this :
NSURL * photoUrl = [NSURL URLWithString:@"https://www.url.com/pic.png"];
NSURLRequest*request = [NSURLRequest requestWithURL:photoUrl];
__weak typeof(UIImageView) *weak_testImage = _testImage;
[_testImage setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"placeHolder.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weak_testImage.image = image;
[button setBackgroundImage:_testImage.image forState:UIControlStateNormal];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
}];
Upvotes: 0