以编程方式创建新的 UiImageView
我想知道在运行时创建新 UIImageView 的循环。我希望每个 UiImageView 有不同的名称。如果用户指定他们想要 100 个图像,则 100 个图像会被适当调整大小并放置在屏幕的特定区域中。他们需要填满一个罐子。与星巴克移动卡应用程序的星星部分类似,不同之处在于可能的图像数量不受限制。
我该怎么做?
编辑:图像视图应该适合下面的罐子:
谢谢
I was wondering about a loop to create new UIImageViews at runtime. I want each UiImageView To Have A Different Name. If the user specifies that they want 100 images, 100 images are appropriately sized an placed in a specific area of the screen. They need to fill up a jar. Similar to the Starbucks Mobile Card App stars section, except there is an unlimited about of possible images.
How would I do this?
EDIT: The Image Views Should Fit Inside The Jar Below:
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
for
循环和NSMutableArray
创建多个UIImageView
,如下所示:或者,如果名称很重要,则创建一个
NSMutableDictionary
并使用-addObject:forKey:
使UIImageView
成为键@"imgName"
的对象或无论你喜欢什么名字。You can create multiple
UIImageView
s using afor
loop and anNSMutableArray
, something like this:Alternately, if the names are important, then create an
NSMutableDictionary
and use-addObject:forKey:
to make theUIImageView
the object for the key@"imgName"
or whatever name you like.关于内存问题的底线:不要允许无限数量的图像。
如果图像填满了一个罐子,为了真实起见,你必须有重叠。如果图像同时显示在屏幕上,用户根本不可能看到一百个不同的图像。
限制用户。你需要把无穷大的概念从你的脑海中赶走。那么你应该没问题。您真正想要的是让您的程序显示大量图像。我不确定你是否打算允许缩放 - 这会让事情变得更加复杂 - 但 iPhone 屏幕上以相同尺寸显示的 100 张图像(不包括你提到的罐子)是 48 像素 x 32 像素。这已经很小了。
我们确实需要更多信息,以便为您提供如何解决此问题的建议。您打算允许缩放吗?图像是否重叠?您希望最小尺寸有多小?等等,等等。
至于多图像视图,PengOne是正确的。
这会将图像添加到 NSMutableArray 中。
您当然必须使用循环将它们添加到屏幕上,并最终将它们从中删除。
Bottom line on the memory issue: Don't allow an infinite number of images.
If the images are filling up a jar, to be realistic you must have overlapping. There is no way in heck the user is going to be able to see one hundred different images if they are all showing onscreen at the same time.
Limit the user. You need to get the concept of infinity out of your head. Then you should be fine. What you really want is for your program to display a lot of images. I'm not sure whether you intend to allow zooming or not - which would complicate things much more - but 100 images displayed across the iPhone screen at equal sizes not including the jar that you mentioned are 48 pixels by 32 pixels. That's already pretty small.
We really need more information in order to advise you as to how to approach this issue. Do you intend to allow zoom? Are the images overlapping or not? how small do you intend for the minimum size to be? etc, etc.
As for the multiple image views, PengOne is correct.
This will add the images to an NSMutableArray.
You will of course have to add them to the screen with a loop and eventually remove them from it.