我有一个带有5个UIImageViews的uiStackView,我需要在运行时更改此imageView中的图像。
现在,我删除所有子视图,生成新的UIImageViews,并像子视图一样添加它,但是这样做对性能不利。我尝试一下:
String presentedPassword = authentication.getCredentials().toString();
if (!passwordEncoder.matches(presentedPassword, client.getPassword())) {
throw new BadCredentialsException("Bad password");
}
我希望有这样的事情
let targetStar = Int(floorf(value * Float(uiStars.subviews.count))) - 1
let factor = CGFloat(min(1, max(self.value, 0)))
let starsCount = uiStars.subviews.count
uiStars.subviews.forEach { $0.removeFromSuperview() }
for i in 0..<starsCount {
if i < targetStar {
let starView = UIImageView(image: star!.maskWithColor(color: UIColor.blue.cgColor, factor: 0))
starView.contentMode = .scaleAspectFit
uiStars.addArrangedSubview(starView)
}
else if i == targetStar {
let starView = UIImageView(image: star!.maskWithColor(color: UIColor.blue.cgColor, factor: factor))
starView.contentMode = .scaleAspectFit
uiStars.addArrangedSubview(starView)
}
else {
let starView = UIImageView(image: star!)
starView.contentMode = .scaleAspectFit
uiStars.addArrangedSubview(starView)
}
}
但这不起作用。
答案 0 :(得分:0)
正在工作:
let targetStar = Int(floorf(value * Float(uiStars.subviews.count))) - 1
let factor = CGFloat(min(1, max(self.value, 0)))
let starsCount = uiStars.subviews.count
for i in 0..<starsCount {
if i < targetStar {
let view = uiStars.subviews[i] as! UIImageView
view.image = star!.maskWithColor(color: UIColor.blue.cgColor, factor: 0)
} else if i == targetStar {
let view = uiStars.subviews[i] as! UIImageView
view.image = star!.maskWithColor(color: UIColor.blue.cgColor, factor: factor)
} else {
let view = uiStars.subviews[i] as! UIImageView
view.image = star!
}
}