大佬教程收集整理的这篇文章主要介绍了swift – UIAlertController – 将自定义视图添加到操作表,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在新的UIAlertController中意识到,我们无法适应任何自定义视图。我可以做什么这样做吗?
我的代码看起来很标准
let alertController = UIAlertController(title: "My AlertController",message: "tryna show some images here man",preferredStyle: UIAlertControllerStyle.ActionSheet) let okAction = UIAlertAction(title: "oks",style: .Default) { (action: UIAlertAction) -> Void in alertController.dismissviewControllerAnimated(true,completion: nil) } let cancelAction = UIAlertAction(title: "Screw it!",style: .Cancel) { (action: UIAlertAction) -> Void in alertController.dismissviewControllerAnimated(true,completion: nil) } alertController.addAction(okAction) alertController.addAction(cancelAction) self.presentViewController(alertController,animated: true,completion: nil)
Swift 3
let alertController = UIAlertController(title: "\n\n\n\n\n\n",message: nil,preferredStyle: UIAlertControllerStyle.actionSheet) let margin:CGFloat = 10.0 let rect = CGRect(x: margin,y: margin,width: alertController.view.bounds.size.width - margin * 4.0,height: 120) let customView = UIView(frame: rect) customView.BACkgroundColor = .green alertController.view.addSubview(customView) let somethingAction = UIAlertAction(title: "Something",style: .default,handler: {(alert: UIAlertAction!) in print("something")}) let cancelAction = UIAlertAction(title: "Cancel",style: .cancel,handler: {(alert: UIAlertAction!) in print("cancel")}) alertController.addAction(somethingAction) alertController.addAction(cancelAction) DispatchQueue.main.async { self.present(alertController,completion:{}) }
迅速
let alertController = UIAlertController(title: "\n\n\n\n\n\n",preferredStyle: UIAlertControllerStyle.actionSheet) let margin:CGFloat = 10.0 let rect = CGRect(x: margin,height: 120) let customView = UIView(frame: rect) customView.BACkgroundColor = .green alertController.view.addSubview(customView) let somethingAction = UIAlertAction(title: "Something",handler: {(alert: UIAlertAction!) in print("something")}) let cancelAction = UIAlertAction(title: "Cancel",handler: {(alert: UIAlertAction!) in print("cancel")}) alertController.addAction(somethingAction) alertController.addAction(cancelAction) self.present(alertController,completion:{})
Objective-C的
UIAlertController *alertController = [UIAlertController alertControllerWithtitle:@"\n\n\n\n\n\n" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; CGFloat margin = 8.0F; UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(margin,margin,alertController.view.bounds.size.width - margin * 4.0F,100.0F)]; customView.BACkgroundColor = [UIColor greenColor]; [alertController.view addSubview:customView]; UIAlertAction *somethingAction = [UIAlertAction actionWithtitle:@"Something" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}]; UIAlertAction *cancelAction = [UIAlertAction actionWithtitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {}]; [alertController addAction:somethingAction]; [alertController addAction:cancelAction]; [self presentViewController:alertController animated:YES completion:^{}];
话虽如此,一个不那么诡异的方法就是使你自己的视图子类与UIAlertController的UIAlertActionStyle布局类似。事实上,相同的代码在iOS 8和iOS 9中看起来略有不同。
以上是大佬教程为你收集整理的swift – UIAlertController – 将自定义视图添加到操作表全部内容,希望文章能够帮你解决swift – UIAlertController – 将自定义视图添加到操作表所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。