按钮添加网络请求的图片(多线程)(ios自学笔记)
2015-11-05 09:39
441 查看
for (int i=0 ; i<ScrollViewArr.count;
i++) {
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(10+i*(width +10
),10, width, width);
NSString *sitemCode = [[ScrollViewArrobjectAtIndex:i]
objectForKey:@"sitemCode"];
NSString *contsFileNm = [NSStringstringWithFormat:@"%@L.jpg",sitemCode];
NSString *strUrl = [NSStringstringWithFormat:@"http://image1.oshishang.cn/%@%@",
[[ScrollViewArrobjectAtIndex:i]
objectForKey:@"contsPathNm"],contsFileNm];
NSURL *URL = [NSURLURLWithString:strUrl];
dispatch_queue_t xrQueue =dispatch_queue_create("loadImage",NULL);
dispatch_async(xrQueue, ^{
UIImage *img = [UIImageimageWithData:[NSDatadataWithContentsOfURL:URL]];
dispatch_async(dispatch_get_main_queue(), ^{
[button setImage:imgforState:UIControlStateNormal];
});
});
[BrandScrollViewaddSubview:button];
}
BrandScrollView.contentSize =CGSizeMake((ScrollViewArr.count
* width)+((ScrollViewArr.count+1) *
10), 100);
}
i++) {
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(10+i*(width +10
),10, width, width);
NSString *sitemCode = [[ScrollViewArrobjectAtIndex:i]
objectForKey:@"sitemCode"];
NSString *contsFileNm = [NSStringstringWithFormat:@"%@L.jpg",sitemCode];
NSString *strUrl = [NSStringstringWithFormat:@"http://image1.oshishang.cn/%@%@",
[[ScrollViewArrobjectAtIndex:i]
objectForKey:@"contsPathNm"],contsFileNm];
NSURL *URL = [NSURLURLWithString:strUrl];
dispatch_queue_t xrQueue =dispatch_queue_create("loadImage",NULL);
dispatch_async(xrQueue, ^{
UIImage *img = [UIImageimageWithData:[NSDatadataWithContentsOfURL:URL]];
dispatch_async(dispatch_get_main_queue(), ^{
[button setImage:imgforState:UIControlStateNormal];
});
});
[BrandScrollViewaddSubview:button];
}
BrandScrollView.contentSize =CGSizeMake((ScrollViewArr.count
* width)+((ScrollViewArr.count+1) *
10), 100);
}
相关文章推荐
- Python3写爬虫(四)多线程实现数据爬取
- C#实现多线程的同步方法实例分析
- oracle em 按钮乱码解决办法及em网页变成英文
- css文本框与按钮美化效果代码
- 用CSS实现的一张图完成的按钮效果
- 浅谈chuck-lua中的多线程
- C#简单多线程同步和优先权用法实例
- C#多线程学习之(四)使用线程池进行多线程的自动管理
- C#多线程编程中的锁系统(三)
- css样式之区分input是按钮还是文本框的方法第1/4页
- C#多线程学习之(六)互斥对象用法实例
- 基于一个应用程序多线程误用的分析详解
- C#多线程学习之(三)生产者和消费者用法分析
- C#多线程学习之(一)多线程的相关概念分析
- C#多线程之Thread中Thread.IsAlive属性用法分析
- C#控制台下测试多线程的方法
- Ruby 多线程的潜力和弱点分析
- ON_COMMAND_RANGE多个按钮响应一个函数的解决方法
- C#中WPF使用多线程调用窗体组件的方法
- C#如何对多线程、多任务管理(demo)