这个问题在这里已经有了答案:
Best Answer-推荐答案 strong>
这就是我的工作方式:
import UIKit
func getRandomColor() -> UIColor {
let randomRed:CGFloat = CGFloat(drand48())
let randomGreen:CGFloat = CGFloat(drand48())
let randomBlue:CGFloat = CGFloat(drand48())
return UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
}
let standardFrame = CGRect(x: 0, y: 0, width: 200, height: 40)
let rootView = UIView(frame: standardFrame)
rootView.backgroundColor = UIColor.blueColor()
let views = [UIView(), UIView(), UIView()]
for view in views {
view.backgroundColor = getRandomColor()
view.bounds.size = CGSize(width: 40, height: 40)
}
let stack = UIStackView(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
stack.backgroundColor = UIColor.redColor()
stack.addArrangedSubview(views[0])
stack.addArrangedSubview(views[1])
stack.addArrangedSubview(views[2])
stack.axis = .Horizontal
stack.alignment = .Fill
stack.distribution = .FillEqually
stack.spacing = 5
rootView.addSubview(stack)
关于ios - UIStackView 布局有什么问题?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/39774033/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) |
Powered by Discuz! X3.4 |