Swift在UIScrollView中搜索具有特定属性的UIImageView



我有一个UIScrollView,里面有1000个UIImages。这些UIImages有一个row和col属性。如何在UIScrollView的UIImages中搜索特定的行和列?(然后我会更新图像(我得到了这个错误:因为在循环中需要"UIScrollView"符合"Sequence">

类似于:

for eachImageView in MyUIScrollView! {
if eachImageView.row = searchrow {
if eachImageView.col = searchcol {
// do something
}
}
}

每个ImageView行和列的MyUIScrollView子视图只是一个类的Int:

class cellUIImageView: UIImageView {
var row: Int = 0
var col: Int = 0
...

首先,注意:类名应该以大写字母开头。。。使用CellUIImageView而不是cellUIImageView

不管怎样。。。

你可以找到这样的观点:

let v2 = scroll.subviews.filter {
($0 as? CellUIImageView)?.row == searchrow && ($0 as? CellUIImageView)?.col == searchcol
}
guard v2.count == 1, let foundView = v2.first as? CellUIImageView else {
print("CellUIImageView with row:", searchrow, "and col:", searchcol, "was not found!")
return
}
// do something with it, such as
foundView.image = replacementImage

相关内容

  • 没有找到相关文章

最新更新