码迷,mamicode.com
首页 > 编程语言 > 详细

获取图片(swift)

时间:2015-07-09 09:45:34      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:swift

获取相机(swift)

by 伍雪颖


@IBActionfunc takePhoto(sender:AnyObject) {
 
view.endEditing(true)
 
moveViewDown()
 
 
let imagePickerActionSheet =UIAlertController(title:"Snap/Upload Photo",
    message:
nil, preferredStyle: .ActionSheet)
 
 
ifUIImagePickerController.isSourceTypeAvailable(.Camera) {
   
let cameraButton =UIAlertAction(title:"Take Photo",
      style: .
Default) { (alert) ->Voidin
       
let imagePicker =UIImagePickerController()
        imagePicker.
delegate =self
        imagePicker.
sourceType = .Camera
       
self.presentViewController(imagePicker,
          animated:
true,
          completion:
nil)
    }
    imagePickerActionSheet.
addAction(cameraButton)
  }
 
 
let libraryButton =UIAlertAction(title:"Choose Existing",
    style: .
Default) { (alert) ->Voidin
     
let imagePicker =UIImagePickerController()
      imagePicker.
delegate =self
      imagePicker.
sourceType = .PhotoLibrary
     
self.presentViewController(imagePicker,
        animated:
true,
        completion:
nil)
  }
  imagePickerActionSheet.
addAction(libraryButton)
 
 
let cancelButton =UIAlertAction(title:"Cancel",
    style: .
Cancel) { (alert) ->Voidin
  }
  imagePickerActionSheet.
addAction(cancelButton)
 
 
presentViewController(imagePickerActionSheet, animated:true,
    completion:
nil)
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

获取图片(swift)

标签:swift

原文地址:http://blog.csdn.net/rainlesvio/article/details/46812029

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!