I have a UITextView in a UIView that I would like the user to be able to show and hide by tapping on it. The UITextView and a constraint of 10 on each side. Currently when a user taps on the view the text does disappear, however you can still see where the UITextView is because there is about one line of space where the UITextView was.
Here is the code I use to adjust the visibility of the UITextView:
if(collapseArray[indexPath.row]){
cell.noteText?.text = nil
}else{
cell.noteText?.text = notesArray[indexPath.row]
}
I have tried setting the .isHidden attribute but I get the same results. I was able to get the desired result when I used a UILabel however I would like the text to be editable.
Here is what I am talking about
As you can see there is still a large about of space below the word test, which is a UILabel that has constraints of 10 all the way around.
Here is the code I used for the given answer below:
class NoteTableViewCell: UITableViewCell, UITextViewDelegate {
@IBOutlet weak var noteTitle: UILabel!
@IBOutlet weak var noteText: UITextView!
@IBOutlet weak var cardView: UIView!
var textViewHeightConstraint: NSLayoutConstraint!
override class func awakeFromNib() {
textViewHeightConstraint = noteText.heightAnchor.constraint(equalToConstant: 0)
textViewHeightConstraint.priority = .defaultLow
textViewHeightConstraint.isActive = true
}
}
however this gives me the error:
Instance member 'noteText' cannot be used on type 'NoteTableViewCell'

