我在我的应用程序中使用了tabbar、navigationBar和SegmentedBar。
我必须显示一张来自HTTP的图片,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
// build the URL, perform the request and show the picture
NSURL *url = [NSURL URLWithString: @"http://api.clementhallet.be/15avril.png"];
//UIImage
[[UIImageView alloc] initWithImage:image];
image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
image.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
}它正在运行,但图片并不是我想要的。
感谢你的帮助!
发布于 2011-04-27 23:06:35
这应该是正确的顺序:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:imageView];你必须设置你的图像视图的帧来定位。如果不是在接口构建器中完成,则如下所示:
image.frame = CGRectMake(x, y, width, height);https://stackoverflow.com/questions/5806180
复制相似问题