简体   繁体   English

将图像从UIImagepicker插入到UICollectionViewCell Swift中

[英]Inserting An Image from UIImagepicker into UICollectionViewCell Swift

Hey just wondering if its possible to Select a specific image from the photolibrary and implement into a Collection View 嘿,只是想知道是否有可能从光库中选择特定图像并实现到“收藏夹视图”中

so the idea is to have an image the user can select from the photolibrary then fill the selected image into a cell within the collection view i would also like to be able to save the image so if the user deletes the photo from the library it remains within the application ( was thinking i could save the image within firebase or NSUserdefaults? 因此,想法是让用户可以从照相馆中选择一个图像,然后将所选图像填充到集合视图中的一个单元格中,我也希望能够保存该图像,因此,如果用户从库中删除了该照片,它仍会保留在应用程序内(以为我可以将图像保存在Firebase或NSUserdefaults中?

A controller demonstrating how to select photos to display in a collection view can be found here . 可以在此处找到演示如何选择照片以在收藏夹视图中显示的控制器。

If you're only going to be saving a single image, then putting it at a known path like demonstrated here would work: How to save a remote image with Swift? 如果仅保存单个图像,则将其放在如此处所示的已知路径下将起作用: 如何使用Swift保存远程图像?

If you're trying to manage multiple images, it's probably a good idea to look into Core Data and have it manage the images' UIImageJPEGRepresentation NSData for you. 如果您要管理多个图像,最好查看Core Data并让它为您管理图像的UIImageJPEGRepresentation NSData。 (Be sure to set "Store in External Record File" for the image data record if you do this!) (如果要这样做,请确保为图像数据记录设置“存储在外部记录文件中!”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM