我有一个TextView。
我怎样才能使两个链接都可以工作并且您可以编辑TextView?
我该如何做,以便当我发布到TextView的链接时,可以单击它并翻阅它(并用其他颜色突出显示它)。
我试图在设置中包括“链接”,但无法编辑TextView。
如何检查剪贴板上是否有内容?
如果剪贴板上有内容,则执行某个操作,如果没有,则执行另一个操作(如示例代码所示)
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) 我有SettingsVC(“照片”有2个开关)和MainVC(“ Code”有一个用于添加触觉反馈按钮的功能)。
我如何才能做到这一点,以便当您关闭“设置”中的“开关”时,该功能将停止工作?
@IBAction func Vib(_ sender: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
}
Run Code Online (Sandbox Code Playgroud) 我在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) 如何使用我的尺寸在窗口中打开模态 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)
例子:
当我单击该单元格以打开MPMediaPickerController时,它将在启动时打开。
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) swift ×6
ios ×5
xcode ×3
alarm ×1
clipboard ×1
copy ×1
hyperlink ×1
uitableview ×1
uitextview ×1