Code create label and button that hide the label. But when run code and press button to hide label, it take long time to hide. Please help me, how to fix this problem?
import UIKit
class ViewController: UIViewController {
@IBOutlet var label: UILabel!
override func viewDidLoad( ) {
super.viewDidLoad ( )
label = UILabel(frame: CGRect(x: 30, y: 30, width: 300, height: 30))
label.text = "Hey"
label.textColor = UIColor.black
self.view.addSubview(label)
let button = UIButton(frame: CGRect(x: 40, y: 500, width: 300, height: 40))
button.setTitle.setTitle("Change label text", for: .normal)
button.setTitleColor(UIColor.black, for: .normal)
button.backgroundColor = UIColor.gray
button.addTarget(self, action: #selector(hide), for: .touchUpInside)
self.view.addSubview(button)
}
@IBAction func hide(_ sender: Any){
self.label.isHidden = true
print("Check")
}
}
I also set print "Check" on action to see button have been activate or not. Once I press button, text "Check" show but button very slow to hide (take around 15 sec). Any advise to fix this problem?