簡體   English   中英

在iOS滾動視圖中動態顯示圖像

[英]Images dynamically in iOS scrollview

我正在開發一個iOS應用程序,並且試圖將圖像動態地放在滾動視圖中。

我聲明了scrollview並將圖像放入其中。 圖像顯示在正確的位置,但是scrollview不滾動。

這是我的代碼:

imagesScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,screenWidth,screenHeight];

for (int i =0; i<dim; i++) {  //dim is the number of the images to show

NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:previewImage_URL]];
previewImages = [UIImage imageWithData:data];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,10+(200*i),screenWidth,200)];

[imageView setImage:previewImages];

[imagesScrollView addSubview:imageView];

}

我怎樣才能做到這一點?

您必須使用

[imageScrollView setContentSize:CGSizeMake(100,200)];

您需要將scrollview的內容大小調整為大於scrollview的大小,因此scrollview可以滾動到某些內容。 在這種情況下,可以使用以下命令設置顯示所有圖像所需的最小內容大小:

[imageScrollView setContentSize:CGSizeMake(screenWidth, 10+(200*(dim - 1)) + 200)];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM