我正在使用我的应用程序中的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]];
}
它正在运行,但图片不是我想要的地方[确切] [1]。
感谢帮助我!
答案 0 :(得分:1)
这应该是正确的顺序:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 100, 100);
[self.view addSubview:imageView];
您必须设置imageview的框架以进行定位。如果没有在界面构建器中完成,请执行以下操作:
image.frame = CGRectMake(x, y, width, height);