我想使用SDWeb
Image设置UIButton背景图像.
代码: –
[btn.imageView setImageWithURL:[NSURL URLWithString:@"image url here"] placeholderImage:[UIImage imageNamed:@"placeholder"]];
谢谢
解决方法
SDWebImage中有这样的方法:
SDWebImage / SDWebImage / UIButton+WebCache.h
在你的班上导入这个文件:
#import <SDWebImage/UIButton+WebCache.h>
使用以下任一方法:
- (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;