博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用户头像设置之ios版本
阅读量:6867 次
发布时间:2019-06-26

本文共 2645 字,大约阅读时间需要 8 分钟。

hot3.png

1.实现这些Delegate,UIActionSheetDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate 2.为了方便测试添加两个控件            var btnChoose = UIButton(frame: CGRect(x: 20, y: 40, width: 100, height: 50))                btnChoose.setTitle("设置照片", forState: UIControlState.Normal)        btnChoose.backgroundColor = UIColor.grayColor()                btnChoose.addTarget(self, action: "chooseImgAction", forControlEvents: UIControlEvents.TouchUpInside)                self.view.addSubview(btnChoose)                                imgShow = UIImageView(frame: CGRect(x: 20, y: 120, width: 100, height: 100))                imgShow.backgroundColor = UIColor.grayColor()        self.view.addSubview(imgShow)                 3.实现各种点击事件和弹出框       func chooseImgAction() {                        var sheet:UIActionSheet                if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))        {            sheet = UIActionSheet(title: "选择头像", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "从相册选择","拍照")        }else                    {            sheet = UIActionSheet(title:"选择头像", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: nil, otherButtonTitles: "从相册选择")        }                        sheet.showInView(self.view)    }            func actionSheet(actionSheet: UIActionSheet, clickedButtonAtIndex buttonIndex: Int)    {        var sourceType = UIImagePickerControllerSourceType.PhotoLibrary        if(buttonIndex != 0)        {            if(buttonIndex==1)            {                //相册                sourceType = UIImagePickerControllerSourceType.PhotoLibrary            }else{                sourceType = UIImagePickerControllerSourceType.Camera            }            let imagePickerController:UIImagePickerController = UIImagePickerController()            imagePickerController.delegate = self            imagePickerController.allowsEditing = true//true为拍照、选择完进入图片编辑模式            imagePickerController.sourceType = sourceType            self.presentViewController(imagePickerController, animated: true, completion:                {            })        }    }                  func imagePickerControllerDidCancel(picker:UIImagePickerController)      {        self.dismissViewControllerAnimated(true, completion: nil)    }            func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {          imgShow.image = image        self.dismissViewControllerAnimated(true, completion: nil)            }

转载于:https://my.oschina.net/jesonzhang/blog/475265

你可能感兴趣的文章
《抓住听众心理——演讲者要知道的100件事》一20.人们学习的最优长度是20分钟...
查看>>
《JUnit实战(第2版)》—第2章2.1节探索JUnit核心
查看>>
Docker背后的内核知识:命名空间资源隔离
查看>>
《圣殿祭司的ASP.NET4.0专家技术手册》---- 1-13 ClientBuilderManager类别的编译功能...
查看>>
《Java编码指南:编写安全可靠程序的75条建议(英文版)》—— 2.7 修复错误...
查看>>
《Redis入门指南(第2版)》一3.2 字符串类型
查看>>
《Adobe Flash Professional CC经典教程》——1.3 使用“库”面板
查看>>
《Android应用开发入门经典(第3版)》——导读
查看>>
xmemcached发布1.3.6
查看>>
《Nmap渗透测试指南》—第6章6.4节IP欺骗
查看>>
Samba 系列(九):将 CentOS 7 桌面系统加入到 Samba4 AD 域环境中
查看>>
《C Primer Plus(第6版)中文版》一第1章 初识C语言1.1 C语言的起源
查看>>
《C语言及程序设计》实践参考——当年第几天
查看>>
前端使用fis3开启本地服务器,并实现热加载功能
查看>>
看BAT技术面试官如何挑选Java程序员
查看>>
AI强势来袭,锁上手机就真的安全了吗?
查看>>
Spring 中的 context
查看>>
重构代码(应如写诗)
查看>>
Vue混入mixins
查看>>
前阿里 P9 级员工称离婚是模拟测试,已回滚复婚!
查看>>