专业java、php、iOS、C++、网页设计、平面设计、网络营销、游戏开发、前端与移动开发培训机构
照片选择器删除照片
点击删除按钮,删除对应的图片
在
photoSelectorCellDidClickDeleteButton
方法里面获取到点击cell
的indexPath
,将photos
数组中对应的图片删除, 刷新collectionView
/// 删除按钮点击了 func photoSelectorCellDidClickDeleteButton(cell: HMPhotoSelectorCell) { // 先获取点击的是哪个位置的删除按钮 let indexPath = collectionView?.indexPath(for: cell) photos.remove(at: indexPath!.item) collectionView?.reloadData() }
设置按钮图片的填充模式
/// 加号按钮 /// 加号按钮 private lazy var addButton: UIButton = { let button = UIButton() button.setImage(UIImage(named: "compose_pic_add"), for: UIControlState.normal) button.addTarget(self, action: #selector(addButtonDidClick), for: .touchUpInside) button.contentMode = UIViewContentMode.scaleAspectFill return button }()