今天学习头像上传第一课:实现UI界面
常见的效果是,点击头像,底部弹出选择框(拍照,本地获取,取消)。今天就来实现这个效果
自iOS8起,苹果就建议告警框使用UIAlertController来代替UIAlertView和UIActionSheet
下面实现一种常见的效果,头像的选取,底部弹出方式(拍照,本地获取,取消)
xcode7.2版本,ios9.1版本,swift2.0
//弹出底部警告框 func showActionSheet(){ let alert = UIAlertController(title:nil,message: nil,preferredStyle: UIAlertControllerStyle.ActionSheet) let openImagesAction = UIAlertAction(title:"从本地获取",style:UIAlertActionStyle.Default,handler: {(alerts:UIAlertAction)-> Void in print("你点击了打开相册按钮")}) let openCameraAction = UIAlertAction(title:"拍照",style:UIAlertActionStyle.Destructive,handler: {(alerts:UIAlertAction)-> Void in print("你点击了打开相机按钮")}) let cancleAction = UIAlertAction(title:"取消",style: UIAlertActionStyle.Cancel,handler:{(alerts:UIAlertAction)->Void in print("你点击了取消按钮")}) alert.addAction(openCameraAction) alert.addAction(openImagesAction) alert.addAction(cancleAction) self.presentViewController(alert,animated: true,completion: nil) }
参考:http://www.hangge.com/blog/cache/detail_651.html