【发布时间】:2020-10-16 23:38:38
【问题描述】:
这里我有这个问题,我有一个 stackView 它包含 5 个元素,它们被赋予了 topAnchor、leading、bottom、traling 和 padding,它们具有相同的宽度大小,我想更改 SelectPhoto : 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
}
** 当我为选择照片图像调用锚函数时**
错误:
"<0x6000034a30c0 uibutton:0x7ffa1d40a580 registrationforgithub.customtextfield:0x7ffa1e808800.top><0x6000034a0730 v:>0x6000034a0730>0x6000034a30c0>
标签: ios swift layout autolayout storyboard