如何简化我的代码 - UIImage imageNamed:

发布于 2024-07-25 23:34:54 字数 1653 浏览 2 评论 0原文

更多 iPhone 内容... 有谁知道我如何削减这段代码。 所以我不必写每一个图像。

多谢

bMon01.animationImages = [NSArray arrayWithObjects: 
                    [UIImage imageNamed:@"mon01_0001.png"],
                    [UIImage imageNamed:@"mon01_0002.png"],
                    [UIImage imageNamed:@"mon01_0003.png"],
                    [UIImage imageNamed:@"mon01_0004.png"],
                    [UIImage imageNamed:@"mon01_0005.png"],
                    [UIImage imageNamed:@"mon01_0006.png"],
                    [UIImage imageNamed:@"mon01_0007.png"],
                    [UIImage imageNamed:@"mon01_0008.png"],
                    [UIImage imageNamed:@"mon01_0009.png"],
                    [UIImage imageNamed:@"mon01_0010.png"],
                    [UIImage imageNamed:@"mon01_0011.png"],
                    [UIImage imageNamed:@"mon01_0012.png"],
                    [UIImage imageNamed:@"mon01_0013.png"],
                    [UIImage imageNamed:@"mon01_0014.png"],
                    [UIImage imageNamed:@"mon01_0015.png"],
                    [UIImage imageNamed:@"mon01_0016.png"],
                    [UIImage imageNamed:@"mon01_0017.png"],
                    [UIImage imageNamed:@"mon01_0018.png"],
                    [UIImage imageNamed:@"mon01_0019.png"],
                    [UIImage imageNamed:@"mon01_0020.png"],
                    [UIImage imageNamed:@"mon01_0021.png"],
                    [UIImage imageNamed:@"mon01_0022.png"],
                    [UIImage imageNamed:@"mon01_0023.png"],
                    [UIImage imageNamed:@"mon01_0024.png"],
                    [UIImage imageNamed:@"mon01_0025.png"], nil];

More iPhone stuff...
Does anyone know how I can trim this code down. So I don't have to write every single image.

Thanks a lot

bMon01.animationImages = [NSArray arrayWithObjects: 
                    [UIImage imageNamed:@"mon01_0001.png"],
                    [UIImage imageNamed:@"mon01_0002.png"],
                    [UIImage imageNamed:@"mon01_0003.png"],
                    [UIImage imageNamed:@"mon01_0004.png"],
                    [UIImage imageNamed:@"mon01_0005.png"],
                    [UIImage imageNamed:@"mon01_0006.png"],
                    [UIImage imageNamed:@"mon01_0007.png"],
                    [UIImage imageNamed:@"mon01_0008.png"],
                    [UIImage imageNamed:@"mon01_0009.png"],
                    [UIImage imageNamed:@"mon01_0010.png"],
                    [UIImage imageNamed:@"mon01_0011.png"],
                    [UIImage imageNamed:@"mon01_0012.png"],
                    [UIImage imageNamed:@"mon01_0013.png"],
                    [UIImage imageNamed:@"mon01_0014.png"],
                    [UIImage imageNamed:@"mon01_0015.png"],
                    [UIImage imageNamed:@"mon01_0016.png"],
                    [UIImage imageNamed:@"mon01_0017.png"],
                    [UIImage imageNamed:@"mon01_0018.png"],
                    [UIImage imageNamed:@"mon01_0019.png"],
                    [UIImage imageNamed:@"mon01_0020.png"],
                    [UIImage imageNamed:@"mon01_0021.png"],
                    [UIImage imageNamed:@"mon01_0022.png"],
                    [UIImage imageNamed:@"mon01_0023.png"],
                    [UIImage imageNamed:@"mon01_0024.png"],
                    [UIImage imageNamed:@"mon01_0025.png"], nil];

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

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

发布评论

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

评论(1

墨小沫ゞ 2024-08-01 23:34:54

这会有所帮助吗:

NSMutableArray *array = [NSMutableArray array];
for (int i = 1; i <= 25; i++) 
  [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%04d.png",i]]];

bMon01.animationImages = array;

Will this help:

NSMutableArray *array = [NSMutableArray array];
for (int i = 1; i <= 25; i++) 
  [array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"mon01_%04d.png",i]]];

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