Swift – Replicate Twitter’s Photo Viewer

Image previewer like Twitter

Introducing you DAImagePreview, a replica of the Twitter’s Photo Viewer done in Swift. Just download and import the file to your project and I will show you how to use it.

My example will show you how to use it inside UICollectionView.

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
        let img = imgs[indexPath.row]
        
        let cell = collectionView.cellForItemAtIndexPath(indexPath) as! CustomCell
        let frame = CGRectMake(cell.frame.origin.x, collectionView.frame.origin.y + cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height)
        
        let imgPreview = DAImagePreview(frame: self.view.frame)
        imgPreview.pickedImg = UIImage(named: img);
        imgPreview.imageFrame = frame;
        self.view.addSubview(imgPreview)
    }

I really hope that this tutorial helped you to create a replica of Twitter’s Photo Viewer. If you have any questions please leave a comment in the comments section. Also, spread the word by sharing this post and subscribe to my newsletter for more awesome Swift tutorials and news.

Recommended for you: How to convert HTML using NSAttributedString

Leave a Reply

Your email address will not be published. Required fields are marked *