Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find X-value position of a label inside a view in Swift

I want to calculate the distance between x-value of two squares positioned in a view.

I did not work because in the frame there is also the y-value and do not know how to select only one. how can I add the x-values from the position of the squares?

var redSquare: UIView = UIView()
var blueSquare: UIView = UIView()
var difference : Double = 0.0

func calc() {
difference = redSquare.frame - blueSquare.frame  
}
like image 289
Antonio Viscomi Avatar asked Dec 05 '14 13:12

Antonio Viscomi


1 Answers

difference = Double(redSquare.frame.origin.x - blueSquare.frame.origin.x)
like image 81
Artem Kirienko Avatar answered Sep 19 '22 13:09

Artem Kirienko