首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在xcode中修复图片的嵌入

如何在xcode中修复图片的嵌入
EN

Stack Overflow用户
提问于 2011-04-27 22:58:04
回答 1查看 882关注 0票数 0

我在我的应用程序中使用了tabbar、navigationBar和SegmentedBar。

我必须显示一张来自HTTP的图片,如下所示:

代码语言:javascript
复制
- (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]];
}

它正在运行,但图片并不是我想要的。

感谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-27 23:06:35

这应该是正确的顺序:

代码语言:javascript
复制
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]]; 

UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 

imageView.frame = CGRectMake(0, 0, 100, 100); 

[self.view addSubview:imageView];

你必须设置你的图像视图的帧来定位。如果不是在接口构建器中完成,则如下所示:

代码语言:javascript
复制
image.frame = CGRectMake(x, y, width, height);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5806180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档