以编程方式创建新的 UiImageView

发布于 2024-12-08 21:01:17 字数 269 浏览 0 评论 0原文

我想知道在运行时创建新 UIImageView 的循环。我希望每个 UiImageView 有不同的名称。如果用户指定他们想要 100 个图像,则 100 个图像会被适当调整大小并放置在屏幕的特定区域中。他们需要填满一个罐子。与星巴克移动卡应用程序的星星部分类似,不同之处在于可能的图像数量不受限制。

我该怎么做?

编辑:图像视图应该适合下面的罐子: Jar

谢谢

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:
Jar

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗笺 2024-12-15 21:01:17

您可以使用 for 循环和 NSMutableArray 创建多个 UIImageView,如下所示:

NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
for (int i=0; i<100; ++i) {
    UIImageView *imgView = [[UIImageView alloc] init];
    // customize the UIImageView as you like
    [imagesArray addObject:imgView];
    [imgView release];
}

或者,如果名称很重要,则创建一个NSMutableDictionary 并使用 -addObject:forKey: 使 UIImageView 成为键 @"imgName" 的对象或无论你喜欢什么名字。

You can create multiple UIImageViews using a for loop and an NSMutableArray, something like this:

NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
for (int i=0; i<100; ++i) {
    UIImageView *imgView = [[UIImageView alloc] init];
    // customize the UIImageView as you like
    [imagesArray addObject:imgView];
    [imgView release];
}

Alternately, if the names are important, then create an NSMutableDictionary and use -addObject:forKey: to make the UIImageView the object for the key @"imgName" or whatever name you like.

空宴 2024-12-15 21:01:17

关于内存问题的底线:不要允许无限数量的图像。

  1. 如果图像填满了一个罐子,为了真实起见,你必须有重叠。如果图像同时显示在屏幕上,用户根本不可能看到一百个不同的图像。

  2. 限制用户。你需要把无穷大的概念从你的脑海中赶走。那么你应该没问题。您真正想要的是让您的程序显示大量图像。我不确定你是否打算允许缩放 - 这会让事情变得更加复杂 - 但 iPhone 屏幕上以相同尺寸显示的 100 张图像(不包括你提到的罐子)是 48 像素 x 32 像素。这已经很小了。

  3. 我们确实需要更多信息,以便为您提供如何解决此问题的建议。您打算允许缩放吗?图像是否重叠?您希望最小尺寸有多小?等等,等等。

至于多图像视图,PengOne是正确的。

这会将图像添加到 NSMutableArray 中。

NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
for (int i=0; i<100; ++i) {
    UIImageView *imgView = [[UIImageView 分配] init];
    // 根据需要自定义 UIImageView
    [imagesArray addObject:imgView];
    [imgView发布];
}

(来自PengOne

您当然必须使用循环将它们添加到屏幕上,并最终将它们从中删除。

Bottom line on the memory issue: Don't allow an infinite number of images.

  1. 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.

  2. 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.

  3. 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.

NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
for (int i=0; i<100; ++i) {
    UIImageView *imgView = [[UIImageView alloc] init];
    // customize the UIImageView as you like
    [imagesArray addObject:imgView];
    [imgView release];
}

(From PengOne)

You will of course have to add them to the screen with a loop and eventually remove them from it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文