我正在尋找一種方法來查找給定(x,y)座標處UILabel的值(文本)。在Swift中獲取UILabel在座標(x,y)處的值
,其他所有問題似乎是有關獲取標籤的(X,Y),我試圖做相反的事情......
例如(30,40)將返回標籤值在那個位置。
謝謝!
更新
func getLabel(location: CGPoint){
let view = self.view.hitTest(location, withEvent:nil)
//I would like to get the value of the label here but I'm not sure how to.
}
@IBAction func tap(sender: UITapGestureRecognizer) {
var coordinate = sender.locationInView(GraphView?())
getLabel(coordinate)
}
不用協調工作,爲什麼不使用標籤? –
查看標題「在視圖中打擊測試」下的UIView文檔。根據所有的子視圖是否爲標籤,你可以使用'hitTest:withEvent:'或'pointInside:withEvent:'。 –