ImagePickerSheet 是 iOS8 的 iMessage 中看到的那片闪耀的自定义操作表的副本,苹果没有将它作为 UIKit 的一部分。这是我用 Swift 编写的第一个项目。它运行良好,但我可能用简单的 Objective-C 脚本编写了一些代码。如果您发现了什么问题,请不要犹豫,提出问题或发起 pull request。不,ImagePickerSheet 没有苹果图片选择器那样的错误 :)。
我是 Laurin Brandner,我在 Twitter 上。
ImagePickerSheet 的 API 与 UIActionSheet 的 API 相似,因此您应该能够很好地与其协作。
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 使用一个代理方法,类似于 UITableView 的数据源,以获取按钮的标题。结合 stringsdict,这允许轻松翻译各种复数形式。
ImagePickerSheet 使用 Swift 编写,并链接到 Photos.framework
。因此,它需要 iOS 8 或更高版本。
ImagePickerSheet 采用MIT 许可。