[英]How to add views in UIScrollview and then add constraints using storyboard iOS objC
[英]how to add multiple custom views into UIScrollview
我正在開發一個應用程序,我需要以下功能。
滿足以上要求,
我用.xib文件制作了自定義視圖。 並將其添加到scrollview中。
但無法知道如何異步下載圖像並在適當的位置顯示它。
我在這里以網格樣式添加自定義視圖的代碼。
-(void)LazyLoading_display_Objects_in_grid_style
{
for(int i=0; i<[imageListingArray count] ; i++)
{
NSArray *arr = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:nil options:nil];
MyView *myView = (MyView *)[arr objectAtIndex:0];
myView.frame = CGRectMake(x,y,width,height);
myView.imgPhoto setContentMode:UIViewContentModeScaleAspectFit];
myView.imageURL = [NSString stringWithFormat:@"%@",[[imageListingArray objectAtIndex:i] valueForKey:@"name"]];
[myView setBackgroundColor:[UIColor clearColor]];
if(myView.imgPhoto.image == nil)
[myView.actLoading startAnimating];
[myView.imgPhoto setTag:1000+i];
[myView setUserInteractionEnabled:TRUE];
myView.tag = 100+i;
[self.imageListingScrollView addSubview:myView];
if(current_no_of_object_in_row !=noOfObjectInColumn)
{
x =x + width + 8 ;
current_no_of_object_in_row ++;
}
else
{
current_no_of_object_in_row =1;
x = 5;
y = y+ height + 8 ;
}
scrollView_Height = y;
}
int temp = [imageListingArray count]%noOfObjectInColumn;
if(temp>0)
{
NSLog(@"No modulus");
y = y + height+ 10;
}
scrollView_Height = y;
NSLog(@"Scroll Height : %d",scrollView_Height);
[self.imageListingScrollView setContentSize:CGSizeMake(308, scrollView_Height+ 5)];
}
不是創建多個視圖,而是可以使用UITableView。 它既可以用作UIScrollViews,也可以用作網格顯示。 此鏈接可能會幫助您:
http://www.markj.net/iphone-asynchronous-table-image/ http://davidgolightly.blogspot.in/2009/02/asynchronous-image-caching-with-iphone.html https://developer.apple .COM /庫/ IOS /#samplecode / LazyTableImages /簡介/ Intro.html
獲取UITableView實例並將其旋轉為:
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);
table.transform = transform;
U也可能必須同樣旋轉UITableView內的單元格
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2.0f);
cell.transform = transform;
}
如果采用UIScrollView,那么你必須處理內存可能會檢查出問題
您可以嘗試使用AsyncImageView類。 它是UIImage的擴展,允許直接URL的異步下載圖像。 我在很多項目中使用了類似的擴展。 你只需要調用方法
- (void)loadImageWithURL:(NSURL *)URL;
當檢索到數據時,圖像將出現在此視圖中。 https://github.com/nicklockwood/AsyncImageView
如果您為所有iOS用於iOS 6+的UITableView項目,您可以使用UICollectionView類制作網格。 如果您將使用UITableView,則可以在左側和右側創建具有兩個AsyncImageView對象的自定義單元格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.