Installation

OnlyPictures is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'OnlyPictures'Copy the code

Explaination & Live tracker.

onlyPictures.order = .descending
Copy the code

Usage

Add UIView in your outlet, select it and go to Properties -> Identity Inspector, add OnlyHorizontalPictures in class property. OnlyVerticalPictures about to release soon.

     ->     

Create instance of this outlet as below.

@IBOutlet weak var onlyPictures: OnlyHorizontalPictures!
Copy the code

Use DataSource for data assignment & Delegate to get indication of action performed in pictures.

onlyPictures.dataSource = self
onlyPictures.delegate = self
Copy the code

DataSource Methods

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. 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!) // Use any library to allocate your image from url to imageView. I've used AlamofireImage here for async downloading, assigning & caching. } }Copy the code

Reload

Properties

.recentAt

                 .left                                                    .right

                         

onlyPictures.recentAt = .left
Copy the code
.alignment

                   .left                                                             .center                                                      .right

   

onlyPictures.alignment = .left
Copy the code
.countPosition

                   .right                                                .left

                         

onlyPictures.countPosition = .right
Copy the code
.gap

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

                                                    

onlyPictures.gap = 36
Copy the code
.spacing

    .spacing = 0                    .spacing = 2                    .spacing = 4                           .spacing = 4

        

onlyPictures.spacing = 2
Copy the code
.spacingColor

  .spacingColor = .gray                       .spacingColor = .white

          

onlyPictures.spacingColor = UIColor.white
Copy the code
.imageInPlaceOfCount
  • Set image in place of count. If this property set, count properties won’t effect.

          

onlyPictures.imageInPlaceOfCount = UIImage(named:"image_name")
Copy the code

Properties for count

.textColorForCount

onlyPictures.textColorForCount = .red
Copy the code
.fontForCount

onlyPictures.fontForCount = UIFont(name: "HelveticaNeue", size: 18)!
Copy the code
.isHiddenVisibleCount
  • To hide count, set .isHiddenVisibleCount = true. But you can receive count in a following funtion of OnlyPicturesDelegatepictureViewCount(value: Int).
onlyPictures.isHiddenVisibleCount = true
Copy the code

Insert first in .order = .descending

                    

onlyPictures.insertFirst(image: UIImage(named: "p11"), withAnimation: .popup)
Copy the code
Insert last in .order = .descending

                    

onlyPictures.insertLast(image: UIImage(named: "p12"), withAnimation: .popup)
Copy the code
Insert at specific position in .order = .descending, below added at 2nd position

                    

onlyPictures.insertPicture(UIImage(named: "p12"), atIndex: 2, withAnimation: .popup)
Copy the code
Remove first in .order = .descending

                    

onlyPictures.removeFirst(withAnimation: .popdown)
Copy the code
Remove last in .order = .descending

                    

onlyPictures.removeLast(withAnimation: .popdown)
Copy the code
Remove from specific position in .order = .descending, below removed from 2nd position

                    

onlyPictures.removePicture(atIndex: 2, withAnimation: .popdown)
Copy the code
Let’s check how insertion works with dynamic images. remove is same as above.
Insert last in .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!)
}
Copy the code
Insert at specific position in .order = .descending, below added at 2nd position

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!)
}
Copy the code

Author

Kiran Jasvanee,

Skype – kiranjasvanee

LinkedIn – www.linkedin.com/in/kiran-ja…

eMail – [email protected]

License

OnlyPictures is available under the MIT license. See the LICENSE file for more info.