首页 > 解决方案 > 标签隐藏很慢

问题描述

代码创建标签和隐藏标签的按钮。但是当运行代码并按下按钮隐藏标签时,隐藏需要很长时间。请帮助我,如何解决这个问题?

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 switchButton = UIButton(frame: CGRect(x: 40, y: 500, width: 300, height: 40))
    switchButton.setTitle("Change label text", for: .normal)
    switchButton.setTitleColor(UIColor.black, for: .normal)
    switchButton.backgroundColor = UIColor.gray
    switchButton.addTarget(self, action: #selector(hide), for: .touchUpInside)
    self.view.addSubview(switchButton)
    }

    @IBAction func hide(_ sender: Any){
        self.label.isHidden = true
        print("check")
    }
}

UI更新慢

标签: iosswiftxcode

解决方案


推荐阅读