使用UIGestureRecognizer获取UIview的UIabel文字
Use UIGestureRecognizer to get the UIabel text of UIview
我想使用UIGestureRecognizer获取UIview(uiViews)的UILabel(label)的文本值。
但是,在我的代码中出现错误。
请告诉我正确的代码。
func test(){
let uiViews = uiView.instance()//xib instance
uiViews.label.text = "Yeah"
self.addSubview(uiViews)
uiViews.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapped.selected(_:))))
}
@objc func tapped(_ sender: UITapGestureRecognizer) {
print(sender.label.text) //Value of type 'UITapGestureRecognizer' has no member 'label'
}
//Error
Value of type 'UITapGestureRecognizer' has no member 'label'
发送者是 UITapGestureRecognizer,它有一个名为 view
的 属性,它是被点击的视图。使用 (sender.view as? uiView)?.label?.text
与 uiView/label.
互动
我想使用UIGestureRecognizer获取UIview(uiViews)的UILabel(label)的文本值。
但是,在我的代码中出现错误。
请告诉我正确的代码。
func test(){
let uiViews = uiView.instance()//xib instance
uiViews.label.text = "Yeah"
self.addSubview(uiViews)
uiViews.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapped.selected(_:))))
}
@objc func tapped(_ sender: UITapGestureRecognizer) {
print(sender.label.text) //Value of type 'UITapGestureRecognizer' has no member 'label'
}
//Error
Value of type 'UITapGestureRecognizer' has no member 'label'
发送者是 UITapGestureRecognizer,它有一个名为 view
的 属性,它是被点击的视图。使用 (sender.view as? uiView)?.label?.text
与 uiView/label.