我在 viewcontroller.h 中这样做。
@property( nonatomic, strong)IBOutlet UIImageView*showLogo;
在 viewcontroller.m 中,我正在这样做。
NSString*path=@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data ];
_showLogo=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
_showLogo.image=img;
最佳答案
尝试将其直接加载到 _showLogo.image
_showLogo=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 500)];
_showLogo.image = [UIImage imageWithContentsOfURL:@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg"];
[self.view addSubview:_showLogo];
或
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.stboston.com/wp-content/uploads/2012/08/iStock_000004791880_1.jpg"]];
_showLogo.image = [UIImage imageWithData:imageData];
[self.view addSubview:_showLogo];
关于ios - Imageview 根本没有加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24767394/