Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setBackgroundimage in UIButton using SDWebimage

Tags:

ios

sdwebimage

I want to set the UIButton background image using SDWebImage.

Code :-

[btn.imageView setImageWithURL:[NSURL URLWithString:@"image url here"]
                           placeholderImage:[UIImage imageNamed:@"placeholder"]];

Thanks

like image 511
Rushabh Avatar asked Oct 31 '13 10:10

Rushabh


1 Answers

There are method for this in SDWebImage : SDWebImage / SDWebImage / UIButton+WebCache.h

Import this file in your class:

#import <SDWebImage/UIButton+WebCache.h>

Use any of this method:

- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state;
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder;
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state completed:(SDWebImageCompletionBlock)completedBlock;
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletionBlock)completedBlock;
- (void)sd_setBackgroundImageWithURL:(NSURL *)url forState:(UIControlState)state placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
like image 179
CRDave Avatar answered Oct 18 '22 20:10

CRDave