Iphone 如何在xcode中定位图片
我正在应用程序中使用tabbar、navigationBar和SegmentedBar 我必须显示来自HTTP的图片,如下所示:Iphone 如何在xcode中定位图片,iphone,objective-c,uiimage,nsurl,image,Iphone,Objective C,Uiimage,Nsurl,Image,我正在应用程序中使用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/15avri
- (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]
谢谢你帮助我 这应该是正确的顺序:
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的框架以进行定位。如果未在interface builder中完成,请执行以下操作:
image.frame = CGRectMake(x, y, width, height);
image=[UIImage-imageWithData:[NSData-datawithcontentsofull:url]];image.frame=CGRectMake(20,20,100,100);[self.view addSubview:[[UIImageView alloc]initWithImage:image]];->请求非结构或unionAh中的成员“frame”,将图像嵌入UIImageView(
[[UIImageView alloc]initWithImage:image];
)或将其添加到UIView,否则无法设置帧。/UIImage[[UIImageView alloc]initWithImage:image];image=[UIImage-imageWithData:[NSData-datawithcontentsofull:url]];image.frame=CGRectMake(0,0,100,100);//image.frame=CGRectMake(,,);[self.view addSubview:[[UIImageView alloc]initWithImage:image]]代码>给我同样的问题…我在回答中添加了一个例子。请为您的问题添加源代码并格式化,因为在评论中无法重述这些内容。感谢您的支持。我已经更新了我写的第一篇文章,但是它不起作用。我必须做一个出口吗???目前,你是一个简单的视图(之前我有一个ImageView,但我刚刚删除了它)