小编B2F*_*2Fq的帖子

链接到TextView并可以编辑TextView(Swift 4)

我有一个TextView。

我怎样才能使两个链接都可以工作并且您可以编辑TextView

我该如何做,以便当我发布到TextView的链接时,可以单击它并翻阅它(并用其他颜色突出显示它)。

我试图在设置中包括“链接”,但无法编辑TextView。

在此处输入图片说明

xcode hyperlink uitextview swift

5
推荐指数
1
解决办法
489
查看次数

如何检查剪贴板上是否有内容

如何检查剪贴板上是否有内容?

如果剪贴板上有内容,则执行某个操作,如果没有,则执行另一个操作(如示例代码所示)

if (if in the clipboard, that is, then open the VC) {
        let modalViewController = self.storyboard?.instantiateViewController(withIdentifier: "Clipboard") as? ClipboardViewController
        modalViewController?.modalPresentationStyle = .overCurrentContext
        self.present(modalViewController!, animated: true, completion: nil)
} else (if the clipboard is empty then) {
        let alert = UIAlertController(title: "Clipboard is Empty", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert)

        alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: nil))
        alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))

        self.present(alert, animated: true)
}
Run Code Online (Sandbox Code Playgroud)

clipboard ios swift

5
推荐指数
2
解决办法
3306
查看次数

开/关触觉反馈开关(快速)

我有SettingsVC(“照片”有2个开关)和MainVC(“ Code”有一个用于添加触觉反馈按钮的功能)。

我如何才能做到这一点,以便当您关闭“设置”中的“开关”时,该功能将停止工作?

SettingsVC“照片”

@IBAction func Vib(_ sender: UIButton) {
    let generator = UIImpactFeedbackGenerator(style: .light)
    generator.impactOccurred()
}
Run Code Online (Sandbox Code Playgroud)

xcode ios swift haptic-feedback

3
推荐指数
1
解决办法
759
查看次数

复制所选单元格中的数据(快速)

我在UITableViewCell中向左/向右滑动?

我该如何做才能复制所选单元格中的数据?

我尝试使用它:

let cell = self.table.cellForRow(at: indexPath)
UIPasteboard.general.string = cell?.detailTextLabel?.text
Run Code Online (Sandbox Code Playgroud)

但是应用程序崩溃

在此处输入图片说明

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")!
    cell.textLabel?.text = myData[indexPath.row]
    return cell
}

func tableView(_ tableView: UITableView,leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?{
    let closeAction = UIContextualAction(style: .normal, title:  "Close", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
        print("Copy")

            //let cell = self.table.cellForRow(at: indexPath)
            //UIPasteboard.general.string = cell?.detailTextLabel?.text

        success(true)
    })
    closeAction.title = "Copy"
    closeAction.backgroundColor = .purple

    return UISwipeActionsConfiguration(actions: [closeAction])
}
Run Code Online (Sandbox Code Playgroud)

xcode copy uitableview ios swift

3
推荐指数
1
解决办法
971
查看次数

使用我的尺寸在窗口中打开模态 ViewController

如何使用我的尺寸在窗口中打开模态 ViewController?

我尝试使用它,但它不起作用

modalViewController?.view.superview?.frame = CGRect(x:162, y: 333, width: 700,height: 700)
//
modalViewController?.view.superview?.center = self.view.center
Run Code Online (Sandbox Code Playgroud)

代码:

let modalViewController = self.storyboard?.instantiateViewController(withIdentifier: "Clipboard") as? ClipboardViewController
    modalViewController?.modalPresentationStyle = .overCurrentContext
    self.present(modalViewController!, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

例子:

在此处输入图片说明

modalviewcontroller ios swift

2
推荐指数
1
解决办法
1322
查看次数

MPMediaPickerController启动后关闭(快速)

当我单击该单元格以打开MPMediaPickerController时,它将在启动时打开。

gif

class MediaViewController: UITableViewController, MPMediaPickerControllerDelegate

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.section == 2 {
        if indexPath.row == 0 {
           let mediaPicker = MPMediaPickerController(mediaTypes: MPMediaType.anyAudio)
           mediaPicker.delegate = self
           mediaPicker.prompt = "Select song"
           mediaPicker.allowsPickingMultipleItems = false
           self.present(mediaPicker, animated: true, completion: nil)
        }
    }
}

func mediaPicker(_ mediaPicker: MPMediaPickerController, didPickMediaItems  mediaItemCollection:MPMediaItemCollection) -> Void {
}

func mediaPickerDidCancel(_ mediaPicker: MPMediaPickerController) {
    dismiss(animated: true, completion: nil)
    print("MPMediaPickerController - Cancel")
}
Run Code Online (Sandbox Code Playgroud)

alarm mpmediapickercontroller ios swift

2
推荐指数
1
解决办法
271
查看次数