Yellow part is the button:
Inside PanGesture:
case .changed:
tempAngle = atan2(touchPoint.y - nailPoint.y, touchPoint.x - nailPoint.x)
changedAngle = tempAngle
let distance = distanceFromTwoPoints(nailPoint, touchPoint)
drawTempUnitButton(buttonPoint: nailPoint, unitButtonWidth: distance, anchorPoint: currentAnglePoint, angle: tempAngle, button: tempUnitButton, unitValue: distance)
How I create button, both width and height are fixed
func drawTempUnitButton(buttonPoint:CGPoint, unitButtonWidth:CGFloat, anchorPoint:CGPoint, angle:CGFloat, button:UIButton, unitValue:CGFloat){
self.addSubview(button)
button.frame = CGRect(x: buttonPoint.x, y: buttonPoint.y, width: unitButtonWidth, height: 30)
let floatUnitValue = Float(unitValue)
let buttonTxt = String(floatUnitValue)
button.setTitle(buttonTxt, for: .normal)
button.titleLabel?.textAlignment = .center
button.setTitleColor(.red, for: .normal)
button.titleLabel?.font = .boldSystemFont(ofSize: 16)
button.backgroundColor = UIColor.yellow
button.setAnchorPoint(anchorPoint)
let transform = CGAffineTransform(rotationAngle: angle)
button.transform = transform
}
What is the problem with it?