您的位置:首页 > 理论基础 > 计算机网络

按钮添加网络请求的图片(多线程)(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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息