I want to make a book app in which the users will read the chapters in it. I want to add a feature in which the user can highlight text and keep it in the app for future reference. How can I trigger an event (like a button with an icon to highlight) after selecting text in swift? Please help
I have googled this for hours and nothing
//
// ViewController.swift
// platesofned
//
// Created by Mauricio Kiyama on 5/13/19.
// Copyright © 2019 Mauricio Kiyama. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
let myTextView: UITextField = {
let label = UITextField()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "Hello World"
label.isSelected = true
label.textColor = .black
return label
}()
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(myTextView)
myTextView.widthAnchor.constraint(equalToConstant: 100).isActive = true
myTextView.heightAnchor.constraint(equalToConstant: 100).isActive = true
myTextView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
myTextView.topAnchor.constraint(equalTo: view.topAnchor, constant: 100).isActive = true
if let textRange = myTextView.selectedTextRange {
let selectedText = myTextView.text(in: textRange)
print(selectedText)
}
}
}
I want a box that has button after selecting any text.