tapz / MWPhotoBrowserSwift

A simple iOS photo and video browser with grid view, captions and selections. Swift version.
MIT License
44 stars 12 forks source link

Could you give some example file on swift? #1

Open ghost opened 8 years ago

tapz commented 8 years ago

This is how I show the photo browsers:

class MyViewController: UITableViewController, PhotoBrowserDelegate {
    private var photos = [MWPhoto]()

    ...

    func showImageBrowser(images: [MyImage]) {
        photos.removeAll(keepCapacity: true)

        for image in images {
            if let url = NSURL(string: image.url) {
                photos.append(MWPhoto(url: url, caption: image.desc))
            }
        }

        let browser = PhotoBrowser(delegate: self)

        browser.navBarTintColor = Colors.myWhite
        browser.navBarBarTintColor = Colors.myBlue
        browser.navBarTranslucent = false
        browser.toolbarTintColor = Colors.myWhite
        browser.toolbarBackgroundColor = Colors.myBlueTranslucent
        browser.toolbarBarTintColor = Colors.myBlueTranslucent

        browser.displayActionButton = true
        browser.displayNavArrows = false
        browser.displaySelectionButtons = false
        browser.zoomPhotosToFill = true
        browser.alwaysShowControls = false
        browser.autoPlayOnAppear = false
        browser.startOnGrid = photos.count > 1
        browser.enableGrid = photos.count > 1
        browser.hideControlsOnStartup = 1 == photos.count

        let browserNavi = UINavigationController(rootViewController: browser)
        browserNavi.modalTransitionStyle = .CrossDissolve

        if 1 == photos.count {
            browserNavi.modalPresentationStyle = .FullScreen
        }

        navigationController?.presentViewController(browserNavi, animated: true, completion: nil)
    }

    func numberOfPhotosInPhotoBrowser(photoBrowser: PhotoBrowser) -> Int {
        return photos.count
    }

    func photoAtIndex(index: Int, photoBrowser: PhotoBrowser) -> Photo {
        return photos[index]
    }

    func thumbPhotoAtIndex(index: Int, photoBrowser: PhotoBrowser) -> Photo {
        return photos[index]
    }

    func titleForPhotoAtIndex(index: Int, photoBrowser: PhotoBrowser) -> String {
        return photos[index].caption
    }

    func photoBrowserDidFinishModalPresentation(photoBrowser: PhotoBrowser) {
        photoBrowser.dismissViewControllerAnimated(true, completion: nil)
    }

    func actionButtonPressedForPhotoAtIndex(index: Int, photoBrowser: PhotoBrowser) {

    }
}
ghost commented 8 years ago

could you give whole class? with tableview sections? and what is [MyImage]? array with url's?

tapz commented 8 years ago

I can't give the whole class as it's proprietary code. The table view code is in no way related to the photo browser. You could as well launch the photo browser from a button click. You just need to implement PhotoBrowserDelegate functions to any class, which can provide the image urls or the images.

MyImage is just a class, which has an url to the image. The photo browser uses MapleBacon image cache to load the image from the url and set it to a UIImageView.

ghost commented 8 years ago

if i could understand obj-c library example i didn't ask you for swift example. i dont know obj-c and just cant imagine how to implement this code to my project. can you add example project?