最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift中实现弹出列表窗口

Swift crifan 3081浏览 0评论

需要实现类似于这种:

swift popup action list

xcode – Swift alert view (iOS8) with OK and cancel button, which button tapped – Stack Overflow

用了:

                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let cancelAlertAction = UIAlertAction(title: "复制", style: UIAlertActionStyle.Default, handler: copyMessageHandler)
                        actionsAlertController.addAction(cancelAlertAction)
                        let sureAlertAction = UIAlertAction(title: "搜藏", style: UIAlertActionStyle.Destructive, handler: addFavoriteMessageHandler)
                        actionsAlertController.addAction(sureAlertAction)
                        self.presentViewController(actionsAlertController, animated: true, completion: nil)
    func copyMessageHandler(alerAction:UIAlertAction){
        print("copyMessageHandler alerAction=\(alerAction)")
    }
   
    func addFavoriteMessageHandler(alerAction:UIAlertAction){
        print("addFavoriteMessageHandler alerAction=\(alerAction)")
    }

结果显示在最底下了:

换成:

//                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.Alert)

结果:

swift popup window center

swift popup window screen center

ios – how to center a popoverview in swift – Stack Overflow

swift UIAlertController position

ios – How to position a UIAlertController’s view? – Stack Overflow

ios – How to display activity indicator in center of UIAlertController? – Stack Overflow

代码:

//                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
                        let actionsAlertController = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.Alert)
                        let cancelAlertAction = UIAlertAction(title: "复制", style: UIAlertActionStyle.Default, handler: copyHandler)
                        actionsAlertController.addAction(cancelAlertAction)
                        let sureAlertAction = UIAlertAction(title: "搜藏", style: UIAlertActionStyle.Default, handler: addFavoriteHandler)
                        actionsAlertController.addAction(sureAlertAction)
                        self.presentViewController(actionsAlertController, animated: true, completion: nil)

然后可以显示了:

但是:

[部分解决]swift中给回调函数添加参数

此处的action list是水平方式显示的

-》

抽空再去研究:如何让action list是垂直方式的列出来。

转载请注明:在路上 » [已解决]swift中实现弹出列表窗口

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
91 queries in 0.190 seconds, using 22.13MB memory