简体   繁体   English

更改图像iPhone

[英]Changing Images Iphone

A simple question about images. 关于图像的一个简单问题。 I want to display 5 images across a width of a view based on information I am processing. 我想根据我正在处理的信息在视图的整个宽度上显示5张图像。

What control do I use to display the images on iphone and can you please provide a code sample how to set the images source property programatically? 我可以使用什么控件在iPhone上显示图像,请提供代码示例,以编程方式设置图像源属性?

UIImageView UIImageView

Either: 要么:

UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage.png"]];

Or, if the imageView already exists: 或者,如果imageView已经存在:

myImage.image = [UIImage imageNamed:@"someImage.png"];

This would be easiest to do in Interface Builder (create the Image Controls and layout there, then you can set the image property from code). 这在Interface Builder中最容易做到(在此创建Image Controls和布局,然后可以从代码中设置image属性)。 If you do it in code, you will need to create all 5 of these and then lay them out properly using the frame property of each UIImageView 如果您在代码中执行此操作,则需要创建所有这5个代码,然后使用每个UIImageView的frame属性正确地将其布局

Documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html 文档: http : //developer.apple.com/library/ios/#documentation/uikit/reference/UIImageView_Class/Reference/Reference.html

You would want to use a UIImageView to do that. 您可能想使用UIImageView来做到这一点。 You could add these either programmatically or with Interface Builder. 您可以通过编程或使用Interface Builder来添加它们。 To change the image in the image view, you would do something like: 要在图像视图中更改图像,您可以执行以下操作:

[myImageView setImage:[UIImage imageNamed:@"MyImage.png"]];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM