我如何更改 stackView 中的元素或获取元素并更改
how i can change element in stackView or get element and change
这里我有这个问题,我有一个包含 5 个元素的 stackView,它们被赋予了 topAnchor、leading、bottom、traling 和 padding,它们具有相同的宽度大小,我想更改 Select照片:UIButton 宽度,但由于它在 stackView 中,它没有改变,我如何更改或调用数组(stackview)中的元素,并更改?
这就是它应该如何:
创建元素:
let selectImageButton : UIButton = {
let button = UIButton(type: .system)
button.setTitle("Select Photo", for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 28, weight: .light)
button.backgroundColor = .white
button.setTitleColor(#colorLiteral(red: 0.4149784446, green: 0.4487785101, blue: 0.8248928785, alpha: 1), for: .normal)
return button
}()
let userNameTextField : CustomTextField = {
let textField = CustomTextField(padding: 16)
textField.placeholder = "Username"
textField.backgroundColor = .white
return textField
}()
let emailTextField : CustomTextField = {
let textField = CustomTextField(padding: 16)
textField.placeholder = "Email"
textField.keyboardType = .emailAddress
textField.backgroundColor = .white
return textField
}()
添加 StackView:
lazy var stackView = UIStackView(arrangedSubviews: [
selectImageButton,
userNameTextField,
emailTextField,
passwordTextField,
registrationButton
])
限制条件:
fileprivate func addingSettingStackView(_ stackView: UIStackView) {
view.addSubview(stackView)
stackView.axis = .vertical
stackView.spacing = 8
stackView.anchor(top: nil, leading: view.leadingAnchor, bottom: nil, trailing: view.trailingAnchor,padding: .init(top: 0, left: 50, bottom: 0, right: 50))
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 100).isActive = true
}
** 当我为 Select 照片图像调用 Anchor 函数时 **
错误:
"",
""
视图更改后尝试调用 self.view.layoutIfNeeded()
。
这里我有这个问题,我有一个包含 5 个元素的 stackView,它们被赋予了 topAnchor、leading、bottom、traling 和 padding,它们具有相同的宽度大小,我想更改 Select照片:UIButton 宽度,但由于它在 stackView 中,它没有改变,我如何更改或调用数组(stackview)中的元素,并更改? 这就是它应该如何:
创建元素:
let selectImageButton : UIButton = {
let button = UIButton(type: .system)
button.setTitle("Select Photo", for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 28, weight: .light)
button.backgroundColor = .white
button.setTitleColor(#colorLiteral(red: 0.4149784446, green: 0.4487785101, blue: 0.8248928785, alpha: 1), for: .normal)
return button
}()
let userNameTextField : CustomTextField = {
let textField = CustomTextField(padding: 16)
textField.placeholder = "Username"
textField.backgroundColor = .white
return textField
}()
let emailTextField : CustomTextField = {
let textField = CustomTextField(padding: 16)
textField.placeholder = "Email"
textField.keyboardType = .emailAddress
textField.backgroundColor = .white
return textField
}()
添加 StackView:
lazy var stackView = UIStackView(arrangedSubviews: [
selectImageButton,
userNameTextField,
emailTextField,
passwordTextField,
registrationButton
])
限制条件:
fileprivate func addingSettingStackView(_ stackView: UIStackView) {
view.addSubview(stackView)
stackView.axis = .vertical
stackView.spacing = 8
stackView.anchor(top: nil, leading: view.leadingAnchor, bottom: nil, trailing: view.trailingAnchor,padding: .init(top: 0, left: 50, bottom: 0, right: 50))
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 100).isActive = true
}
** 当我为 Select 照片图像调用 Anchor 函数时 **
错误:
"
视图更改后尝试调用 self.view.layoutIfNeeded()
。