gpt4 book ai didi

ios - 使用 UIScrollView 的简单图片库

转载 作者:行者123 更新时间:2023-11-29 10:58:47 24 4
gpt4 key购买 nike

我正在尝试创建一个非常基本的图片库,其中包含三张图片,用户可以滑过并查看图片。

我的解决方案是使用 UIColor

NSArray *colors = [NSArray arrayWithObjects:[UIColor blueColor], [UIColor redColor], [UIColor greenColor], nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = 320 * i;
frame.origin.y = 0;
frame.size = CGSizeMake(320, 208);

UIView *subview = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [colors objectAtIndex:i];
[self.slideshow addSubview:subview];
}

self.slideshow.contentSize = CGSizeMake(320 * [colors count], 208);

但是类似的解决方案不显示图片

NSArray *images = [NSArray arrayWithObjects:[UIImage imageWithContentsOfFile:@"pic_1_3a.jpg"], [UIImage imageWithContentsOfFile:@"pic_1_3b.jpg"], [UIImage imageWithContentsOfFile:@"pic_1_3c.jpg"], nil];
for (int i = 0; i < images.count; i++) {
CGRect frame;
frame.origin.x = 320 * i;
frame.origin.y = 0;
frame.size = CGSizeMake(320, 208);

UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [images objectAtIndex:i];
[self.slideshow addSubview:subview];
}

self.slideshow.contentSize = CGSizeMake(320 * [images count], 208);

有什么想法吗? UIScrollView 存在于 UIView 中。

enter image description here

最佳答案

尝试改变

NSArray *images = [NSArray arrayWithObjects:[UIImage imageWithContentsOfFile:@"pic_1_3a.jpg"], [UIImage imageWithContentsOfFile:@"pic_1_3b.jpg"], [UIImage imageWithContentsOfFile:@"pic_1_3c.jpg"], nil];

NSArray *images = [NSArray arrayWithObjects:[UIImage imageNamed:@"pic_1_3a.jpg"], [UIImage imageNamed:@"pic_1_3b.jpg"], [UIImage imageNamed:@"pic_1_3c.jpg"], nil];

关于ios - 使用 UIScrollView 的简单图片库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17039477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com