用UIStackView作等距的视图

2022-02-17  本文已影响0人  陈藩

用UIStackView作等距的视图


截屏2022-02-17 上午8.51.05.png
    let stackView = UIStackView()
    stackView.backgroundColor = UIColor.red
    stackView.frame = CGRect.init(x: 20, y: 20, width: UIScreen.main.bounds.size.width - 20 * 2, height: 100)
    
    stackView.alignment = .fill
    stackView.spacing = 10.0
    stackView.axis = .vertical
    stackView.distribution = .fill
    
    self.view.addSubview(stackView)
    
    let lab_1 = UILabel()
    lab_1.backgroundColor = UIColor.blue
    lab_1.text = "hello world,hello china"
    stackView.addArrangedSubview(lab_1)
    
    let lab_2 = UILabel()
    lab_2.backgroundColor = UIColor.yellow
    lab_2.text = "hello world"
    stackView.addArrangedSubview(lab_2)
    
    let lab_3 = UILabel()
    lab_3.backgroundColor = UIColor.green
    lab_3.text = "hello"
    stackView.addArrangedSubview(lab_3)
上一篇 下一篇

猜你喜欢

热点阅读