【发布时间】:2021-03-14 16:04:22
【问题描述】:
func createTabBar() {
var arrangedSubviews = [UIView]()
if let menus = CMSessionManager.sharedInstance.menus {
for menu_item in menus {
if let menuInfoDetails = menu_item as? [String: Any] {
let tabButton = CustomButton(color: .red, titleString: menuInfoDetails["label"] as! String)
// This apparently has no effect on button size
tabButton.frame = CGRect(x: 100, y: 100, width: 100, height: 50)
arrangedSubviews.append(tabButton)
}
}
stackView.alignment = .leading
stackView = UIStackView(arrangedSubviews: arrangedSubviews)
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.distribution = .fillProportionally
stackView.axis = .horizontal
stackView.spacing = 8
self.view.addSubview(stackView)
stackView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 24).isActive = true
stackView.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 0).isActive = true
stackView.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true
}
}
我一直在尝试以编程方式更改按钮大小:
tabButton.frame = CGRect(x: 100, y: 100, width: 100, height: 50)
无论我设置哪个高度或宽度,或 x y 位置,都不会改变。
知道有什么问题吗?
【问题讨论】: