相册

在plist文件中

Privacy - Photo Library Usage Description

头文件

import "WPhotoViewController.h"

表格协议以及全局变量

UIButton *_addBut;
UITableView *_tableView;
NSMutableArray *_photosArr;

[self createTableView];
_addBut = [UIButton buttonWithType:UIButtonTypeCustom];
_addBut.frame = CGRectMake((self.view.frame.size.width-160phoneScale)/2, self.view.frame.size.height-(60+160)phoneScale, 160phoneScale, 160phoneScale);
_addBut.layer.cornerRadius = 160*phoneScale/2;
_addBut.layer.masksToBounds = YES;
[_addBut setImage:[UIImage imageNamed:@"1.2.1-CreateNew"] forState:UIControlStateNormal];
[_addBut addTarget:self action:@selector(addButClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_addBut];
-(void)addButClick
{
WPhotoViewController *WphotoVC = [[WPhotoViewController alloc] init];
//选择图片的最大数
WphotoVC.selectPhotoOfMax = 8;
[WphotoVC setSelectPhotosBack:^(NSMutableArray *phostsArr) {
_photosArr = phostsArr;
[_tableView reloadData];
}];
[self presentViewController:WphotoVC animated:YES completion:nil];
}
-(void)createTableView
{
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:_tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _photosArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellId = [NSString stringWithFormat:@"cellId%ld", (long)indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CGFloat photoSize = [UIScreen mainScreen].bounds.size.width - 20;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(10, 10, photoSize, photoSize);
imageView.image = [[_photosArr objectAtIndex:indexPath.row] objectForKey:@"image"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.layer.masksToBounds = YES;
[cell addSubview:imageView];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [UIScreen mainScreen].bounds.size.width;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • UIView+SGFrame.h #import @interface UIView (SGFrame) @pro...
    超越时空的思念_8a22阅读 1,969评论 1 1
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,306评论 3 38
  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 10,963评论 3 3
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,679评论 1 32
  • 作为一个典型狮子座的九零后,脾气得有多暴躁可想而知。 步入社会之前,我习惯于按自己的想法和方式去解...
    藜罂阅读 380评论 0 0

友情链接更多精彩内容