UIImageView加载网络图片,NSOperationQueue来异步加载图片
来源:互联网 发布:小学生的英语软件 编辑:程序博客网 时间:2024/05/16 18:56
#import "newDetailViewController.h"#import "Common.h"#import "newObject.h"#import "NetRequest.h"#import <UIKit/UIKitDefines.h>@interface newDetailViewController ()<UIWebViewDelegate>{ UILabel *GWDetailTitleText; UILabel *GWDetailTitleText1; UITextView *GWDetailContentText; UIImageView *imageview; NSURL *url; UIView *opaqueview; UIActivityIndicatorView *activityIndicator; }@end@implementation newDetailViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { self.view.bounds = CGRectMake(0, -20, self.view.frame.size.width, self.view.frame.size.height ); } } return self;}- (void)viewDidLoad{ [UIApplication sharedApplication].statusBarHidden = YES; [super viewDidLoad]; //[self initView];}-(void)initView{ UIButton *loginButton = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 40, 0, 40, 30)]; [loginButton setTitle:@"返回" forState:UIControlStateNormal]; loginButton.titleLabel.textColor =[UIColor blackColor]; [loginButton addTarget:self action:@selector(backtofather) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:loginButton]; GWDetailTitleText = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, SCREEN_WIDTH - 20, 40)]; GWDetailTitleText.textAlignment = NSTextAlignmentCenter; GWDetailTitleText.numberOfLines = 0; GWDetailTitleText.lineBreakMode = UILineBreakModeCharacterWrap; [self.view addSubview:GWDetailTitleText]; GWDetailTitleText1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 70, SCREEN_WIDTH - 20, 20)]; GWDetailTitleText1.textAlignment = NSTextAlignmentLeft; [self.view addSubview:GWDetailTitleText1]; web = [[UIWebView alloc]initWithFrame:CGRectMake(10, 100, SCREEN_WIDTH - 20, self.view.bounds.origin.y + self.view.bounds.size.height - 110)]; web.scalesPageToFit = YES; web.delegate = self; [[web layer] setCornerRadius:10]; [web setClipsToBounds:YES]; web.scalesPageToFit = NO; for (id subview in web.subviews) { if ([[subview class] isSubclassOfClass: [UIScrollView class]]) { ((UIScrollView *)subview).bounces = NO; } } web.backgroundColor = [UIColor whiteColor]; [self.view addSubview:web]; // GWDetailContentText = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, SCREEN_WIDTH - 20, self.view.bounds.origin.y + self.view.bounds.size.height - 110)];// GWDetailContentText.layer.borderWidth = 1;// GWDetailContentText.editable = NO;// [self.view addSubview:GWDetailContentText];}-(void)setchoicedDate:(newObject *)myarray{ [self initView]; MyLog(@"%@ ", myarray ); //MyLog(@"%@", myarray[0]);//[@"rel_title"] GWDetailTitleText.text = myarray.rel_title; NSString *date =[[NSString alloc]initWithString:myarray.rel_date]; date = [date substringToIndex:10]; NSString *mystring = [NSString stringWithFormat:@"发布人:%@ 日期:%@",myarray.rel_user,date]; GWDetailTitleText1.text = mystring; MyLog(@"%@",myarray.rel_picpath); if (![myarray.rel_picpath isEqualToString:@"null"]) { url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",@"http://www.xf0573.com",myarray.rel_picpath]]; imageview = [[UIImageView alloc]initWithFrame:CGRectMake(80, 0, 160, 120)]; imageview.layer.masksToBounds = YES; imageview.layer.cornerRadius = 5.0f; [imageview setBackgroundColor:[UIColor grayColor]]; imageview.image = [UIImage imageNamed:@"moren.png"]; [web addSubview:imageview]; opaqueview = [[ UIView alloc] initWithFrame: CGRectMake(0, 0, 160, 120)]; activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake( 0, 0, 160, 120)]; [ opaqueview setBackgroundColor:[UIColor blackColor]]; [ opaqueview setAlpha:0.6 ]; [ imageview addSubview: opaqueview]; [ opaqueview addSubview: activityIndicator]; [ activityIndicator startAnimating ]; opaqueview.hidden = NO ; web1 = [[UIWebView alloc]initWithFrame:CGRectMake(10, 120, SCREEN_WIDTH - 20, self.view.bounds.origin.y + self.view.bounds.size.height - web.frame.origin.y - 130)]; web1.scalesPageToFit = YES; web1.delegate = self; [[web1 layer] setCornerRadius:10]; [web1 setClipsToBounds:YES]; web1.scalesPageToFit = NO; for (id subview in web1.subviews) { if ([[subview class] isSubclassOfClass: [UIScrollView class]]) { ((UIScrollView *)subview).bounces = NO; } } web1.backgroundColor = [UIColor whiteColor]; [web1 loadHTMLString:myarray.rel_content baseURL:nil]; [web addSubview:web1]; NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init]; NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadImage) object:nil]; [operationQueue addOperation:op]; //[web loadRequest:req]; }else if ([myarray.rel_picpath isEqualToString:@"null"]) { [web loadHTMLString:myarray.rel_content baseURL:nil]; //GWDetailContentText.text = myarray.rel_content; }}- (void)downloadImage{ UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; imageview.image = image; [activityIndicator stopAnimating]; opaqueview.hidden = YES ;}-(void)backtofather{ [self dismissModalViewControllerAnimated:YES];}@end
0 0
- UIImageView加载网络图片,NSOperationQueue来异步加载图片
- UIImageView异步加载网络图片
- UIImageView异步加载网络图片
- UIImageView异步加载网络图片
- uiimageview 异步加载图片
- UIImageView加载网络图片,NSOperationQuene异步加载图片
- iOS-UIImageView加载网络下载的图片(异步+多线程)
- 异步加载网络图片
- 网络图片异步加载
- 异步加载网络图片
- 异步加载网络图片
- IOS 图片异步加载 - UIImageView(AFNetworking)
- Android 图片异步加载 加载网络图片
- UIImageView加载图片
- Android异步加载网络图片
- Android 异步加载网络图片
- Android网络图片异步加载
- Android异步加载网络图片
- hdu 4035 Maze(期望)
- 安装nrpe时提示错误:configure: error: cannot find ssl headers怎么办?
- HSV颜色空间下标示数据类型
- 使用UIImageView展现来自网络的图片
- 夺宝奇兵
- UIImageView加载网络图片,NSOperationQueue来异步加载图片
- 获取两个日期的时间差(天数、时、分、秒)
- 11个cocos2d-x2.2.3经典游戏源代码
- js去掉html标签和去掉字符串文本的所有的空格
- OpenGL学习之统计图形
- win7(64位)平台下Cygwin+Eclipse搭建Hadoop单机开发环境 (二) Hadoop的安装
- Enable PO approval process to send PO in PDF format via email
- 设计模式、框架、架构
- [Qt总结篇]最后总结