UIStackView本身的backgroundColor和layer属性设置无效。
如果要实现设置背景和边框等属性,只能通过addSubview形式;
let view = UIView(frame: .zero)
view.autoresizingMask = [.flexibleWidth, .flexibleHeight];
view.backgroundColor = UIColor.orange;
view.layer.cornerRadius = 5;
view.layer.borderColor = UIColor.lightGray.cgColor
view.layer.borderWidth = 1;
stackView.addSubview(view);
网友评论