I have 3 subViews(2 labels, 1 UITextView) each with different background colour in my VC. I want to show them based on the flag value. The issue is when the UITextview’s text empty, the textView has some default width and height(which i did not give) with its background colour whether labels are not taking any width if text is empty
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var alertTitle: UILabel!
@IBOutlet weak var alertSubtitle: UITextView!
@IBOutlet weak var alertMessage: UILabel!
var fullText: String? = "dfjgjkd dkjfghjkdg kjdfhkgjh kjfdhkgjhdfkj kjdfshgkj"
var flag: Bool = true
override func viewDidLoad() {
super.viewDidLoad()
changeText(str: fullText, toggle: flag)
}
@IBAction func changeText(_ sender: Any) {
flag = !flag
changeText(str: fullText, toggle: flag)
}
func changeText(str: String? = "", toggle: Bool) {
alertTitle.text = toggle ? fullText: nil
alertSubtitle.text = !toggle ? fullText : nil
alertMessage.text = toggle ? fullText: nil
}
}