iOS 开发之 为UIButton添加类别方法加载网络图片
来源:互联网 发布:思维导图软件mac版 编辑:程序博客网 时间:2024/06/05 19:25
UIButton+WebCache.h
#import <UIKit/UIKit.h>
// 为Button添加类别方法
@interface UIButton (WebCache)
- (void)xr_setButtonImageWithUrl:(NSString *)urlStr;
@end
UIButton+WebCache.m
#import "UIButton+WebCache.h"
@implementation UIButton (WebCache)
- (void)xr_setButtonImageWithUrl:(NSString *)urlStr {
NSURL * url = [NSURL URLWithString:urlStr];
// 根据图片的url下载图片数据
dispatch_queue_t xrQueue = dispatch_queue_create("loadImage", NULL); // 创建GCD线程队列
dispatch_async(xrQueue, ^{
// 异步下载图片
UIImage * img = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
// 主线程刷新UI
dispatch_async(dispatch_get_main_queue(), ^{
[self setImage:img forState:UIControlStateNormal];
});
});
}
@end
- iOS 开发之 为UIButton添加类别方法加载网络图片
- iOS 开发之 为UIButton添加类别方法加载网络图片
- iOS开发学习笔记之swift3.0几种加载网络图片的方法
- iOS为类别添加属性的方法(RunTime)
- iOS给UIButton添加类别,批量添加Button
- IOS开发之UIButton
- IOS开发之UIButton
- iOS开发之UIButton
- iOS开发之UIButton
- iOS开发之UIButton
- 给UIButton添加(类别)方法,方便批量创建button
- ios-图片加载方式类别和优缺点
- iOS开发之证书类别
- IOS开发总结之UIButton常用属性和方法
- iOS类别扩展无法识别添加方法
- iOS类别扩展无法识别添加方法
- IOS开发之UIButton详解
- iOS 开发之设置UIButton
- Service implementation URL not specified
- C:\fakepath\"+文件名的形式路径问题
- C#十六进制颜色与Color对象的互相转换
- python中使用epoll开发服务端程序
- mysql一主多从同步配置
- iOS 开发之 为UIButton添加类别方法加载网络图片
- iOS 继承 UIWindow 的密码保护功能
- 移动物体监控系统的设计与开发完整版
- IOS NSindexpath创建
- 高效率字符串比较函数
- AidlTokenType.import or android:layout_height="match_parent"
- ffmpeg源码编译
- Android 如何获取在strings里面设置的值
- 【转载】iOS静态库与动态库