TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | May 2015 |
SPMSupports SPM | ✗ |
Maintained by Laurin Brandner.
ImagePickerSheet is a duplicate of that shiny new custom action sheet seen in iOS8’s iMessage that Apple didn’t make part of UIKit. It’s the first project I’ve written in Swift. It works well but I might have coded something the Objective-C kind of way. Don’t hesitate to open an issue or pull request if you spotted something. And no, ImagePickerSheet does not have the glitches Apple’s image picker has :)
I’m Laurin Brandner, I’m on Twitter.
ImagePickerSheet’s API is similar to the one of UIActionSheet so you should get along with it just well.
let sheet = ImagePickerSheet()
sheet.numberOfButtons = 3
sheet.delegate = self
sheet.showInView(view)
func imagePickerSheet(imagePickerSheet: ImagePickerSheet, titleForButtonAtIndex buttonIndex: Int) -> String {
let photosSelected = (imagePickerSheet.numberOfSelectedPhotos > 0)
if (buttonIndex == 0) {
if photosSelected {
return NSLocalizedString("Add comment", comment: "Add comment")
}
else {
return NSLocalizedString("Take Photo Or Video", comment: "Take Photo Or Video")
}
}
else {
if photosSelected {
return NSString.localizedStringWithFormat(NSLocalizedString("ImagePickerSheet.button1.Send %lu Photo", comment: "The secondary title of the image picker sheet to send the photos"), imagePickerSheet.numberOfSelectedPhotos) as String
}
else {
return NSLocalizedString("Photo Library", comment: "Photo Library")
}
}
}
func imagePickerSheet(imagePickerSheet: ImagePickerSheet, willDismissWithButtonIndex buttonIndex: Int) {
if buttonIndex != imagePickerSheet.cancelButtonIndex {
if imagePickerSheet.selectedPhotos.count > 0 {
println(imagePickerSheet.selectedPhotos)
}
else {
let controller = UIImagePickerController()
controller.delegate = self
controller.sourceType = (buttonIndex == 2) ? .PhotoLibrary : .Camera
presentViewController(controller, animated: true, completion: nil)
}
}
}
ImagePickerSheet uses a delegate method, similar to UITableView’s dataSource, to get the title of a button. In conjunction with stringsdict, this allows for easy translation of various plural forms.
ImagePickerSheet is written in Swift and links against Photos.framework
. It therefore requires iOS 8 or later.
ImagePickerSheet is licensed under the MIT License.