日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios swift5 弹出原生的提示框(弹框) UIAlertController

發(fā)布時間:2023/12/31 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios swift5 弹出原生的提示框(弹框) UIAlertController 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

文章目錄

  • 1.從中間彈出,限制textfield的內(nèi)容長度
    • 1.1 截圖
    • 1.2 代碼
    • 1.3 參考
  • 2.從下面彈出
    • 2.1 截圖
    • 2.2 代碼
  • 3.其他舉例
    • 3.1 下面只有一個確定按鈕(帶截圖和代碼)
    • 3.2 只有代碼
  • 4.參考博客

1.從中間彈出,限制textfield的內(nèi)容長度

1.1 截圖

1.2 代碼

func renameAlert() {let cell: UITableViewCell = tableView.cellForRow(at: IndexPath(row: 0, section: 1))!let alertController = UIAlertController(title: NSLocalizedString("vehicleRename", comment: ""),message: nil, preferredStyle: .alert)let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)let okAction = UIAlertAction(title: "確定", style: .default, handler: {action inprint("點擊了確定")let textField: UITextField = (alertController.textFields?[0])!;print(textField.text)cell.detailTextLabel?.text = textField.text//跳到定位設(shè)置})alertController.addTextField { (textfield) inprint("打印")//這個block會在彈出對話框的時候調(diào)用,這個參數(shù)textfield就是系統(tǒng)為我們創(chuàng)建的textfieldtextfield.delegate = selfprint(textfield)}alertController.addAction(cancelAction)alertController.addAction(okAction)self.present(alertController, animated: true, completion: nil)}extension settingVC: UITextFieldDelegate {func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {if range.location >= 6 {return false}return true}}

1.3 參考

限制UITextField輸入長度的方法

2.從下面彈出

2.1 截圖

2.2 代碼

func bottomAlert() {let alertController = UIAlertController(title: NSLocalizedString("unitSwitch", comment: ""),message: nil, preferredStyle: .actionSheet)let cancelAction = UIAlertAction(title: NSLocalizedString("cancel", comment: ""), style: .cancel, handler: nil)let cell: UITableViewCell = tableView.cellForRow(at: IndexPath(row: 1, section: 1))!let kmAction = UIAlertAction(title: NSLocalizedString("km", comment: ""), style: .default, handler: {action inprint("點擊了公里")cell.detailTextLabel?.text = NSLocalizedString("km", comment: "")//跳到定位設(shè)置})let milesAction = UIAlertAction(title: NSLocalizedString("miles", comment: ""), style: .default, handler: {action inprint("點擊了英里")cell.detailTextLabel?.text = NSLocalizedString("miles", comment: "")})alertController.addAction(cancelAction)alertController.addAction(kmAction)alertController.addAction(milesAction)self.present(alertController, animated: true, completion: nil)}

3.其他舉例

3.1 下面只有一個確定按鈕(帶截圖和代碼)

func haveBindAlert(){let alertController = UIAlertController(title: "設(shè)備已經(jīng)被綁定",message: nil, preferredStyle: .alert)let okAction = UIAlertAction(title: "確定", style: .cancel, handler: nil)alertController.addAction(okAction)self.present(alertController, animated: true, completion: nil)}

3.2 只有代碼

let alertController = UIAlertController(title: "需要定位權(quán)限",message: "用于提高精確的定位及導(dǎo)航服務(wù)", preferredStyle: .alert)let cancelAction = UIAlertAction(title: "暫不設(shè)置", style: .cancel, handler: nil)let okAction = UIAlertAction(title: "去設(shè)置", style: .default, handler: {action inprint("點擊了確定")//跳到定位設(shè)置})alertController.addAction(cancelAction)alertController.addAction(okAction)self.present(alertController, animated: true, completion: nil)

4.參考博客


上圖的效果參考下面這個博客:
UIAlertController使用

參考博客:
Swift UIAlertController的用法

相關(guān)博客:
ios原生彈框UIAlertController(oc版)

總結(jié)

以上是生活随笔為你收集整理的ios swift5 弹出原生的提示框(弹框) UIAlertController的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。