OnlyPictures 1.1.2

OnlyPictures 1.1.2

测试测试
语言语言 SwiftSwift
许可 MIT
发布最新发布2017年11月
SwiftSwift 版本4.0
SPM支持 SPM

Kiran Jasvanee维护。



  • Kiran Jasvanee



                         

                         

                         

                         

                         



Twitter Codecov Pods Version Platforms Issues Forks Stars Stars


安装

OnlyPictures可以通过CocoaPods获取。要安装
它,只需将以下行添加到您的Podfile中

pod 'OnlyPictures'

解释和实时跟踪器。

onlyPictures.order = .descending

用法

在您的outlet中添加 UIView,选择它并转到 属性 ->> 身份检查器,在 类属性 中添加 OnlyHorizontalPicturesOnlyVerticalPictures 即将推出。

     ->     

按照以下方式创建此outlet的 实例

@IBOutlet weak var onlyPictures: OnlyHorizontalPictures!

使用 DataSource 进行数据分配,并使用 Delegate 来获取在图片中执行的动作的指示。

onlyPictures.dataSource = self
onlyPictures.delegate = self

DataSource 方法

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!)   
    }
}

Delegate 方法

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) 以重新排列图片。

属性

.order
  • 图片基于 LIFO - 后进先出工作,意味着最后添加的将在顶部显示(最近)。
  • 如果您的数组包含按 递增 排序的图片,它将显示最后一张图片,或者换句话说,最后添加的图片在顶部(最近)。
  • 如果您的数组包含按 递减 排序的图片,将 .order 属性 设置为 .descending 以在顶部显示第一张图片(最近)。

            .ascending                                      .descending

                         

onlyPictures.order = .descending
.recentAt

                 .left                                                    .right

                         

onlyPictures.recentAt = .left
.alignment

                   .left                                                .center                                                .right

   

onlyPictures.alignment = .left
.countPosition

                   .right                                                .left

                         

onlyPictures.countPosition = .right
.gap

           .gap = 20                                      .gap = 36                                                .gap = 50

                                                    

onlyPictures.gap = 36
.spacing

    代码:.spacing = 0                    .spacing = 2                    .spacing = 4                       .spacing = 4

        

onlyPictures.spacing = 2
spacingColor

  代码:.spacingColor = .gray                       .spacingColor = .white

          

onlyPictures.spacingColor = UIColor.white
imageInPlaceOfCount
  • 设置图像代替计数。如果此属性已设置,则计数属性将不会生效。

          

onlyPictures.imageInPlaceOfCount = UIImage(named:"image_name")

计数属性的设置

backgroundColorForCount

onlyPictures.backgroundColorForCount = .orange
textColorForCount

onlyPictures.textColorForCount = .red
fontForCount

onlyPictures.fontForCount = UIFont(name: "HelveticaNeue", size: 18)!
isHiddenVisibleCount
  • 要隐藏计数,请设置 .isHiddenVisibleCount = true。但您可以在 OnlyPicturesDelegate 的下一个函数中收到计数 - pictureViewCount(value: Int)
onlyPictures.isHiddenVisibleCount = true

您可以额外执行的操作,插入/移除在第一个/最后一个/特定位置的图片

  • 注意:插/移图像是您应负责的任务,您在图片集合中使用与 Satoshi vardom 等同的模式。
.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 文件。