【问题标题】:how create multiple image view design?如何创建多个图像视图设计?
【发布时间】:2016-05-27 08:22:04
【问题描述】:

我需要在我的应用程序中显示类似图像的视图。我很困惑为此使用什么,我可以使用集合视图还是我必须使用视图和 imageViews 和按钮来设计我自己。 任何帮助或建议将不胜感激。

【问题讨论】:

标签: ios objective-c uitableview uicollectionview ui-design


【解决方案1】:

还有另一种方法可以通过自定义单元格来做到这一点...

1. UIImageview 随心所欲....(这里我连续拿了4个)

2.获取图像名称数组。(可以根据我们的获取生成)

现在可以参考下面的UITableView数据源代码......

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{        
  return arrImage.count %4 ? arrImage.count /4 +1 :arrImage.count /4;
} 




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 static NSString *strCellIdentifier = @"Cell";
 TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:strCellIdentifier];
if (cell == nil) {

    cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strCellIdentifier];
}
NSUInteger imageIndex = (indexPath.row*4);//indexPath.row *(number of images on a row)
//First image of the row
    cell.image1.image = [UIImage imageNamed:[arrImage objectAtIndex:imageIndex +0]];
//Second image of the row
if (arrImage.count > imageIndex+1){
    cell.image2.image = [UIImage imageNamed:[arrImage objectAtIndex:imageIndex +1]];
}
//Third image of the row
if (arrImage.count > (imageIndex+2)){
    cell.image3.image = [UIImage imageNamed:[arrImage objectAtIndex:imageIndex +2]];
}
//Fourth image of the row
if (arrImage.count > (imageIndex+3)){
    cell.image4.image = [UIImage imageNamed:[arrImage objectAtIndex:imageIndex +3]];
}
cell.backgroundColor = [UIColor redColor];
return cell;
}

【讨论】:

    【解决方案2】:

    请执行以下代码。

    ViewController.m

    static CGFloat EdgeInsets;
    @property (strong, nonatomic) IBOutlet UICollectionView *collectionVeiw;
    @property (strong, nonatomic) NSMutableArray *arrImages;
    
    #pragma mark - View Life Cycle
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        EdgeInsets = 30;
        _arrImages = [NSMutableArray alloc]init];
    }
    
    #pragma mark - Collection View delegate methods
    
    - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section{
        return _arrImages.count;
    }
    
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
        ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCell" forIndexPath:indexPath];
        if (cell == nil)
            cell = [[[NSBundle mainBundle] loadNibNamed:@"ImageCell" owner:self options:nil] objectAtIndex:0];
    
        cell.imgView.image = [UIImage imageNamed:@"1.png"];
        [cell.btnDelete addTarget:self action:@selector(btnDeleteTapped:) forControlEvents:UIControlEventTouchUpInside];
        cell.btnDelete.tag = indexPath.row;
        return cell;
    }
    
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    }
    
    - (void)btnDeleteTapped:(UIButton*)sender{
        [_arrImages removeObjectAtIndex:sender.tag];
        [_collectionView reloadData];
    }
    
    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
        CGFloat width = [UIScreen mainScreen].bounds.size.width-(EdgeInsets);
        return CGSizeMake(width/2, width/2);
    }
    

    也许这对你有帮助。

    【讨论】:

    • 如果需要任何帮助,请告诉我。
    猜你喜欢
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 2016-11-07
    • 1970-01-01
    相关资源
    最近更新 更多