0

I need a multiple textview on UIImage like this.

I want add multiple view(text+labels) in my imageView.

enter image description here

Thanks-

iDeveloper
  • 2,339
  • 2
  • 24
  • 38

2 Answers2

0

Hope this idea will help you.

  • Get X / Y Axis on touch event.
  • 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)
    }
    
Hasya
  • 9,792
  • 4
  • 31
  • 46
  • Thank you for this good idea But I want resizing, change rotate and change text options by touching. – Abdullah Kanza Oct 24 '16 at 11:18
  • Get more on - http://stackoverflow.com/questions/28717634/swift-how-can-you-rotate-text-for-uibutton-and-uilabel http://www.ioscreator.com/tutorials/dragging-views-gestures-tutorial-ios8-swift – Hasya Oct 24 '16 at 11:47
  • https://www.raywenderlich.com/76020/using-uigesturerecognizer-with-swift-tutorial https://github.com/stropdale/Draggable-UIView – Hasya Oct 24 '16 at 11:56
0

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.

Community
  • 1
  • 1