用于电话号码的iOS Slide Up菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于电话号码的iOS Slide Up菜单相关的知识,希望对你有一定的参考价值。

ios上有解决方案我可以创建这样的电话号码选择器菜单吗? Apple会自动支持此视图还是应该单独实现此视图?

enter image description here

答案

这在iOS中称为UIAlertController的ActionSheet样式。您可以使用以下代码显示ActionSheet:

        let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
    let action1 = UIAlertAction(title: "Phone", style: .default) { (action) in
        // Add your code here when Phone action Tapped
    }
    let action2 = UIAlertAction(title: "Mobile", style: .default) { (action) in
        // Add your code here when Mobile action Tapped
    }
    let action3 = UIAlertAction(title: "iPhone", style: .default) { (action) in
        // Add your code here when iPhone action Tapped

    }
    let action4 = UIAlertAction(title: "Private", style: .default) { (action) in
        // Add your code here when Private action Tapped

    }
    let cancel = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
        // Add your code here when Cancel action Tapped

    }

    // To set image in ActionButton
    action1.setValue(#imageLiteral(resourceName: "check").withRenderingMode(.alwaysOriginal), forKey: "image")

    // Add Actions to AlertController
    actionSheet.addAction(action1)
    actionSheet.addAction(action2)
    actionSheet.addAction(action3)
    actionSheet.addAction(action4)
    actionSheet.addAction(cancel)

    // Present UIAlertController
    present(actionSheet, animated: true, completion: nil)

enter image description here

另一答案

您可以使用UIActionSheet根据您的要求创建自己的菜单

let actionSheet = UIActionSheet(title: "Choose Option", delegate: self, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil, otherButtonTitles: "Save", "Delete")
actionSheet.showInView(self.view)

以上是关于用于电话号码的iOS Slide Up菜单的主要内容,如果未能解决你的问题,请参考以下文章

片段交易动画:滑入滑出

iOS常用于显示几小时前/几天前/几月前/几年前的代码片段

从android eclipse中的片段刷新或更新listadapter

上下文菜单不适用于两个片段

带有片段的 Android Up 按钮未显示完整片段

标签菜单android - 不正确的调用片段