程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-UIScrollView批量圖片

ios-UIScrollView批量圖片

編輯:編程綜合問答
UIScrollView批量圖片

在視圖中有一個UIScrollView,要顯示的圖片位於一個數組內,我想要在UIScrollView中顯示圖片,謝謝。

NSMutableArray *images = [[NSMutableArray alloc ] init];

for (int i = 0; i < 10; i++)
{
    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString     stringWithFormat:@"%d/%d.png",b, i]];
    UIImage *img = [UIImage imageWithContentsOfFile:getImagePath];
    [images addObject:img];
    NSLog(@"%@",getImagePath);
    imge.image=img;
}

最佳回答:


設置UIScrollViewcontentSize,然後添加UIImageViewScrollView

[self.myScView addSubView:self.imageView];

添加圖片到單獨的UIImageView

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    self.scrollView.contentSize = CGSizeMake(320, 465);
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];

    int Y = 0;

   // here give you image name is proper so we can access it by for loop.
    for (int i = 1; i <=  totalNumberOFImage; i++)
    {
      UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0, Y, 100, 100)] ;
      [imageView setImage: [UIImage imageNamed:[NSString stringWithFormat:@"youImageName%d", i]]];
      [self.scrollView addSubview: imageView];
      Y = Y + imageView.frame.size.height+5;

     if(y > 465)
      self.scrollView.contentSize = CGSizeMake(320, y);
    }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved