本文介绍了使用SDWebimage在UIButton中设置setBackgroundimage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SDWebImage设置UIButton背景图片。

I want to set the UIButton background image using SDWebImage.

代码: -

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

谢谢

推荐答案

SDWebImage中有这方法:

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;

这篇关于使用SDWebimage在UIButton中设置setBackgroundimage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 04:53