测试测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2017年11月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由Kiran Jasvanee维护。
OnlyPictures可以通过CocoaPods获取。要安装
它,只需将以下行添加到您的Podfile中
pod 'OnlyPictures'
onlyPictures.order = .descending
在您的outlet中添加 UIView
,选择它并转到 属性 ->> 身份检查器
,在 类属性
中添加 OnlyHorizontalPictures
。OnlyVerticalPictures
即将推出。
按照以下方式创建此outlet的 实例
。
@IBOutlet weak var onlyPictures: OnlyHorizontalPictures!
使用 DataSource
进行数据分配,并使用 Delegate
来获取在图片中执行的动作的指示。
onlyPictures.dataSource = self
onlyPictures.delegate = self
extension ViewController: OnlyPicturesDataSource {
// ---------------------------------------------------
// returns the total no of pictures
func numberOfPictures() -> Int {
return pictures.count
}
// ---------------------------------------------------
// returns the no of pictures should be visible in screen.
// In above preview, Left & Right formats are example of visible pictures, if you want pictures to be shown without count, remove this function, it's optional.
func visiblePictures() -> Int {
return 6
}
// ---------------------------------------------------
// return the images you want to show. If you have URL's for images, use next function instead of this.
// use .defaultPicture property to set placeholder image. This only work with local images. for URL's images we provided imageView instance, it's your responsibility to assign placeholder image in it. Check next function.
// onlyPictures.defaultPicture = #imageLiteral(resourceName: "defaultProfilePicture")
func pictureViews(index: Int) -> UIImage {
return pictures[index]
}
// ---------------------------------------------------
// If you do have URLs of images. Use below function to have UIImageView instance and index insted of 'pictureViews(index: Int) -> UIImage'
// NOTE: It's your resposibility to assign any placeholder image till download & assignment completes.
// I've used AlamofireImage here for image async downloading, assigning & caching, Use any library to allocate your image from url to imageView.
func pictureViews(_ imageView: UIImageView, index: Int) {
// Use 'index' to receive specific url from your collection. It's similar to indexPath.row in UITableView.
let url = URL(string: self.pictures[index])
imageView.image = #imageLiteral(resourceName: "defaultProfilePicture") // placeholder image
imageView.af_setImage(withURL: url!)
}
}
extension ViewController: OnlyPicturesDelegate {
// ---------------------------------------------------
// receive an action of selected picture tap index
func pictureView(_ imageView: UIImageView, didSelectAt index: Int) {
}
// ---------------------------------------------------
// receive an action of tap upon count
func pictureViewCountDidSelect() {
}
// ---------------------------------------------------
// receive a count, incase you want to do additionally things with it.
// even if your requirement is to hide count and handle it externally with below fuction, you can hide it using property `isVisibleCount = true`.
func pictureViewCount(value: Int) {
print("count value: \(value)")
}
// ---------------------------------------------------
// receive an action, whem tap occures anywhere in OnlyPicture view.
func pictureViewDidSelect() {
}
}
:reloadData()
reloadData()
将与 UITableView ->> reloadData()
类似工作,它将再次调用 numberOfPictures()
和 pictureViews(index: Int)
/pictureViews(_ imageView: UIImageView, index: Int)
以重新排列图片。LIFO
- 后进先出工作,意味着最后添加的将在顶部显示(最近)。递增
排序的图片,它将显示最后一张图片,或者换句话说,最后添加的图片在顶部(最近)。递减
排序的图片,将 .order 属性
设置为 .descending
以在顶部显示第一张图片(最近)。 .ascending
.descending
onlyPictures.order = .descending
.left
.right
onlyPictures.recentAt = .left
.left
.center
.right
onlyPictures.alignment = .left
.right
.left
onlyPictures.countPosition = .right
.gap = 20
.gap = 36
.gap = 50
onlyPictures.gap = 36
代码:.spacing = 0
.spacing = 2
.spacing = 4
.spacing = 4
onlyPictures.spacing = 2
代码:.spacingColor = .gray
.spacingColor = .white
onlyPictures.spacingColor = UIColor.white
onlyPictures.imageInPlaceOfCount = UIImage(named:"image_name")
onlyPictures.backgroundColorForCount = .orange
onlyPictures.textColorForCount = .red
onlyPictures.fontForCount = UIFont(name: "HelveticaNeue", size: 18)!
.isHiddenVisibleCount = true
。但您可以在 OnlyPicturesDelegate
的下一个函数中收到计数 - pictureViewCount(value: Int)
。onlyPictures.isHiddenVisibleCount = true
.order = .descending
中插入第一个onlyPictures.insertFirst(image: UIImage(named: "p11"), withAnimation: .popup)
.order = .descending
中插入最后一个onlyPictures.insertLast(image: UIImage(named: "p12"), withAnimation: .popup)
.order = .descending
中插入特定位置,下面添加到第 2 个位置onlyPictures.insertPicture(UIImage(named: "p12"), atIndex: 2, withAnimation: .popup)
.order = .descending
中移除第一个onlyPictures.removeFirst(withAnimation: .popdown)
.order = .descending
中移除最后一个onlyPictures.removeLast(withAnimation: .popdown)
.order = .descending
中从特定位置移除,下面从第二个位置移除onlyPictures.removePicture(atIndex: 2, withAnimation: .popdown)
.order = .descending
中插入第一个let url = URL(string: "http://insightstobehavior.com/wp-content/uploads/2017/08/testi-5.jpg")
onlyPictures.insertFirst(withAnimation: .popup) { (imageView) in
imageView.image = #imageLiteral(resourceName: "defaultProfilePicture")
imageView.af_setImage(withURL: url!)
}
.order = .descending
中插入最后一个let url = URL(string: "http://insightstobehavior.com/wp-content/uploads/2017/08/testi-5.jpg")
onlyPictures.insertLast(withAnimation: .popup) { (imageView) in
imageView.image = #imageLiteral(resourceName: "defaultProfilePicture")
imageView.af_setImage(withURL: url!)
}
.order = .descending
中插入特定位置,下面添加到第 2 个位置let url = URL(string: "http://insightstobehavior.com/wp-content/uploads/2017/08/testi-5.jpg")
onlyPictures.insertPicture(atIndex: 2, withAnimation: .popup) { (imageView) in
imageView.image = #imageLiteral(resourceName: "defaultProfilePicture")
imageView.af_setImage(withURL: url!)
}
Kiran Jasvanee,
Skype - kiranjasvanee
LinkedIn - https://www.linkedin.com/in/kiran-jasvanee-ab363778
eMail - [email protected]
OnlyPictures 适用于 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。