
Swift_UIImagePickerController选择图片显示代码如下:
import UIKitclass VIEwController: UIVIEwController,UIImagePickerControllerDelegate,UINavigationControllerDelegate { //跳转图库按钮 var selectbutton:UIbutton! //显示图片 var imageVIEw:UIImageVIEw! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() //创建子视图 createSubVIEws() } //MARK: - 创建子视图 func createSubVIEws() { self.imageVIEw = UIImageVIEw(frame: CGRectMake(80,100,200,200)) self.imageVIEw.backgroundcolor = UIcolor.bluecolor() self.vIEw.addSubvIEw(self.imageVIEw) self.selectbutton = UIbutton(type: UIbuttonType.Custom) self.selectbutton.frame = CGRectMake(160,350,80,40) self.selectbutton.backgroundcolor = UIcolor.purplecolor() self.selectbutton.setTitle("选择图片",forState: UIControlState.normal) self.selectbutton.setTitlecolor(UIcolor.redcolor(),forState: UIControlState.normal) self.selectbutton.TitleLabel?.Font = UIFont.boldSystemFontOfSize(18) //self.selectbutton.addTarget(self,action: Selector(selectimageAction(self.selectbutton)),forControlEvents: UIControlEvents.touchUpInsIDe) //按钮的action:方法 self.selectbutton.addTarget(self,action: "selectimageAction:",forControlEvents: UIControlEvents.touchUpInsIDe) self.vIEw.addSubvIEw(self.selectbutton) } //MARK: buttonAction func selectimageAction(sender: AnyObject) { let imagePC:UIImagePickerController = UIImagePickerController() imagePC.sourceType = UIImagePickerControllerSourceType.Photolibrary imagePC.delegate = self self.presentVIEwController(imagePC,animated: true,completion: nil) print("button click") } //MARK: - UIImagePickerControllerDelegate func imagePickerController(picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [String : AnyObject]) { //print("info = %@",info) print("info = \(info)") /* UIImagePickerControllerOriginalimage,<UIImage: 0x7aedc800> size {4288,2848} orIEntation 0 scale 1.000000 UIImagePickerControllerReferenceURL,assets-library://asset/asset.JPG?ID=7FECF4BC-7660-4CC6-8BD2-39443E4A4181&ext=JPG UIImagePickerControllerMediaType,public.image for (a,b) in info { print("\(a),\(b)") } */ let img = info["UIImagePickerControllerOriginalimage"] as! UIImage self.imageVIEw.image = img picker.dismissVIEwControllerAnimated(true,completion: nil) } internal func imagePickerControllerDIDCancel(picker: UIImagePickerController) { picker.dismissVIEwControllerAnimated(true) { () -> VoID in print("dismiss ok") } } /* overrIDe func dIDReceiveMemoryWarning() { super.dIDReceiveMemoryWarning() // dispose of any resources that can be recreated. } */ } 总结 以上是内存溢出为你收集整理的Swift_UIImagePickerController选择图片显示全部内容,希望文章能够帮你解决Swift_UIImagePickerController选择图片显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)