I need a multiple textview on UIImage like this.
I want add multiple view(text+labels) in my imageView.
Thanks-
I need a multiple textview on UIImage like this.
I want add multiple view(text+labels) in my imageView.
Thanks-
Hope this idea will help you.
Pass X / Y axis information to some function which draw dynamic UItextField
func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
if let touch = touches.first {
let position = touch.location(in: self)
print(position.x)
print(position.y)
}
}
func addDynamicTextField(xAxis: CGFloat, yAxis: CGFloat)
{
let someFrame = CGRect(x: xAxis, y: yAxis, width: 100.0, height: 30.0)
let text = UITextField(frame: someFrame)
imageView.addSubview(text)
}
Check my detailed example here:
How to add interactive UILabels on top of a UIImageView?
The code there add two CALayers that detects taps and changes text. Using the same type of logic, you can add pan/pinch/rotate handlers that will handle move/resize/rotate.
After you wire up the handlers like in that sample, here's the remaining functions:
func moveLayer(_ recognizer:UIPanGestureRecognizer) {
let p = recognizer.location(in: self)
if layer1.editMode {
layer1.position = p
}
if layer2.editMode {
layer2.position = p
}
}
func rotateLayer(_ recognizer:UIRotationGestureRecognizer) {
let p = recognizer.location(in: self)
if layer1.editMode {
layer1.anchorPoint = CGPoint(x: 0.5, y: 0.5)
layer1.transform = CATransform3DRotate(myRedEye.transform, recognizer.rotation, 0.0, 0.0, 1.0); }
if layer2.editMode {
layer2.position = p
}
}
func resizeLayer(_ recognizer:UIPinchGestureRecognizer) {
_ = recognizer.location(in: self)
if layer1.editMode {
layer1.transform = CATransform3DScale(myRedEye.transform, recognizer.scale, recognizer.scale, recognizer.scale)
recognizer.scale = 1
}
if layer2.editMode {
layer2.transform = CGAffineTransformScale(myGreenEye.transform, recognizer.scale, recognizer.scale)
}
}
This was code I wrote a year ago and never put in production. If my memory is good, the trickiest part was how iOS differentiates between a pinch and rotate gesture. Since both use two fingers, combining resizing and rotating led to some small unexpected (IMHO) behaviors.