【问题标题】:how to pass images to UIScrollView如何将图像传递给 UIScrollView
【发布时间】:2014-07-18 14:22:52
【问题描述】:

我有 url。现在我可以获取 Url 的图像。但是现在我需要将 8 张图像传递给 ScrollView。所以请告诉我有关我的问题的任何想法。 我试过这样:-

NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
    for (NSDictionary *diction in al)
    {


        NSString *geting =[diction valueForKey:@"dealimage"];
        NSLog(@"dealimage is %@",geting);

        NSData *getdata=[[NSData alloc]initWithData:[NSData dataFromBase64String:geting]];
        NSLog(@"good day %@",getdata);
        dataimages=[UIImage imageWithData:getdata];
        NSLog(@"dataimages %@",dataimages);

        [imagesarray addObject:dataimages];


    }

当我打印图像数组时它正在显示

images array is array(
    "<UIImage: 0x7539b70>",
    "<UIImage: 0x7176e00>",
    "<UIImage: 0x7182960>",
    "<UIImage: 0x7185d40>",
    "<UIImage: 0x7541d00>",
    "<UIImage: 0x7186e30>",
    "<UIImage: 0x7186ff0>",
    "<UIImage: 0x7187410>"
)

示例:- 请告诉我如何在获取图像时添加滚动。 感谢高级。

【问题讨论】:

  • 使用集合视图。
  • @duci9y 谢谢,但我需要滚动图像,所以请告诉我有关如何滚动图像 CollectionView 的任何想法。当我在 CollectionView 单元格上传递图像时仅显示
  • 集合视图是滚动视图。它滚动。

标签: ios objective-c json uiscrollview uiimageview


【解决方案1】:

您需要将这些图像中的每一个添加为 UIScrollView 的子视图,并将滚动视图的内容大小设置为组合图像的总宽度。这就是您对单个图像执行此操作的方式。

UIImageView *image = [[UIImageView alloc] initWithImage:imagesarray[0]];
[scrollview addSubview:image];
scollview.contentSize = CGSizeMake(image.frame.size.height, image.frame.size.width);

希望能给你一个好的起点。

【讨论】:

  • 我按照你说的尝试了 gettingScrollView =[[UIScrollView alloc]init]; UIImageView *imagescroll = [[UIImageView alloc] initWithImage:imagesarray[0]]; [gettingScrollView addSubview:imagescroll];获取ScrollView.contentSize = CGSizeMake(100, 75); [self.view addSubview:gettingScrollView]; gettingScrollView.frame=CGRectMake(0, 0, 320, 80); imagesarray=[[NSMutableArray alloc]init]; gettingScrollView.backgroundColor=[UIColor yellowColor];但我没有得到图像请帮助我
  • 在将索引 0 处的图像添加到滚动视图后,是否有任何理由重新初始化 imagesarray?
  • k 我在哪里重新初始化请告诉我
  • 在将属于该数组的图像添加到滚动视图后,您会在评论中添加 imagesarray=[[NSMutableArray alloc]init]。我不确定这是否是您的问题,但我不知道您为什么要这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-17
  • 1970-01-01
  • 2023-01-03
  • 2012-03-20
  • 2019-12-26
相关资源
最近更新 更多