作者:hushuoni_133 | 来源:互联网 | 2023-10-11 16:14
//
// StackViewController.swift
// Swift_shop
//
// Created by 彭思 on 2020/5/9.
// Copyright © 2020 HaiDilao. All rights reserved.
//
import UIKit
class StackViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
layoutStackView()
}
func layoutStackView() {
let stackView = stackViewWithAxis(axis: .vertical, alignment: .fill, distribution: .fill)
view.addSubview(stackView)
stackView.snp.makeConstraints { (make) in
make.center.equalTo(self.view)
make.left.equalTo(10)
make.right.equalTo(-10)
}
for i in 0.. UIStackView {
let stackView = UIStackView()
stackView.axis = axis
stackView.alignment = alignment
stackView.distribution = distribution
return stackView
}
func createLabel() -> UILabel {
let label = UILabel()
label.textColor = UIColor.black
label.numberOfLines = 0
label.backgroundColor = UIColor.init(red: CGFloat(arc4random_uniform(256))/255.0, green: CGFloat(arc4random_uniform(256))/255.0, blue: CGFloat(arc4random_uniform(256))/255.0, alpha: 1.0)
return label
}
}
效果图如下: