我正在寻找一种方法来查找给定(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:'。 –