【问题标题】:Changing images of UIImageView in UIStackView在 UIStackView 中更改 UIImageView 的图像
【发布时间】:2019-09-24 04:54:31
【问题描述】:
我有 UIStackView(红色)。当我将这个带有图片的 stackView imageView 放入时,这个 imageView 变成了 UIView,之后即使我想要也无法更改图像。
我有滑块,在我的堆栈视图中有图像更改计数器,以及应该更改我的 imageView 图像的按钮。
Stack View 只包含 UIView,不包含 UIIMAgeView。因此,我无法更改 imageView 图像。
【问题讨论】:
标签:
ios
swift
xcode
uiimageview
uistackview
【解决方案1】:
您需要将stackView.arrangedSubviews 元素转换为UIImageView
@objc func buttonAction(_ sender: UIButton) {
for case let imageView as UIImageView in stackView.arrangedSubviews {
imageView.image = newImage
}
}