ios – setBackgroundimage在UIButton使用SDWebimage

前端之家收集整理的这篇文章主要介绍了ios – setBackgroundimage在UIButton使用SDWebimage前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想使用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;

猜你在找的iOS相关文章