gpt4 book ai didi

ios - 分段控制,更改 UIImageView (以编程方式)Swift 4/5

转载 作者:行者123 更新时间:2023-11-29 05:38:28 25 4
gpt4 key购买 nike

我已将代码包含到分段控件和 UIImageView 中。任何帮助都会很棒,谢谢。

let segmentedControl: UISegmentedControl = {
let sc = UISegmentedControl(items: ["Login", "Register"])
sc.translatesAutoresizingMaskIntoConstraints = false
sc.tintColor = UIColor.white
sc.selectedSegmentIndex = 0

sc.addTarget(self, action: #selector(handleSegmentedControlChange), for: .valueChanged)
return sc
}()
// profile pic
lazy var picture: UIImageView = {
var pic = UIImageView()
if segmentedControl.selectedSegmentIndex == 0 {
pic.image = UIImage(named: "Logo")
} else {
pic.image = UIImage(named: "Profile")

let mytapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView))
mytapGestureRecognizer.numberOfTapsRequired = 1
pic.addGestureRecognizer(mytapGestureRecognizer)
pic.isUserInteractionEnabled = true
}
pic.translatesAutoresizingMaskIntoConstraints = false
pic.contentMode = .scaleAspectFill
return pic
}()

图片应该会改变并启用触摸手势,但它们都不起作用。

最佳答案

将 If-else block 移至 handlerSegmentedControlChange 选择器。

关于ios - 分段控制,更改 UIImageView (以编程方式)Swift 4/5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56796736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com