简体   繁体   English

如何在Swift iOS的集合视图中动态加载URL(如果有图像,则为表单)?

[英]How to dynamically load urls (in the form if images) in collection view in swift ios?

I have this array of names as below 我有这个名称数组如下

["Acting Chief Justice Gita Mittal", "Justice S. Ravindra Bhat", "Justice Sanjiv Khanna", "Justice GS Sistani", "Justice Dr. S. Muralidhar", "Justice Hima Kohli", "Justice Vipin Sanghi", "Justice Siddharth Mridul", "Justice Manmohan"]

and Array of URLs as below 和网址数组如下

["writereaddata%5Cupload%5CJudges/JImage_7ZV0X5SB.JPG", "writereaddata%5Cupload%5CJudges/JImage_31PR55RK.JPG", "writereaddata%5Cupload%5CJudges/JImage_TALSLWYH.JPG", "writereaddata%5Cupload%5CJudges/JImage_DDW7F8I4.JPG", "writereaddata%5Cupload%5CJudges/JImage_8MP3TXZ2.JPG", "writereaddata%5Cupload%5CJudges/JImage_3R72I03Q.JPG", "writereaddata%5Cupload%5CJudges/JImage_ZPL72GGF.JPG", "writereaddata%5Cupload%5CJudges/JImage_RHXYPY1N.JPG", "writereaddata%5Cupload%5CJudges/JImage_BR82DUAU.JPG"]  

I want to display these in collection view in swift on runtime on image and label . 我想在运行时在图像和标签上迅速在集合视图中显示这些内容。 How to do this ? 这个怎么做 ?

Thanks 谢谢

There is a great swift library for downloading and caching images called SDWebImage . 有一个很棒的快速库,用于下载和缓存图像,称为SDWebImage Check the docs it's pretty straightforward. 检查文档,这非常简单。

You can SDWebImage library to load image from URL in TableView and CollectionView. 您可以SDWebImage库从TableView和CollectionView中的URL加载图像。

You like this in UITableView and UICollectionView cell. 您喜欢在UITableViewUICollectionView单元格中这样做。

cell.imageView.sd_setImage(with: URL(string: "yourImageURL"), placeholderImage: UIImage(named: "placeholder.png"))

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

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