1
votes

I have a UITextView with text and UIImageView inside it. The textView resizes according to the device through the use of auto layout constraints.

But whenever the textView is resized the position of the text inside the UITextView also changes dynamically but the ImageView and Bezier path for the specific image remains constant.

The image is related to the text so I want to place it at a specific position in relation to the text. So how to do it using Auto Layout.

I have shown below what I want to achieve. Both images have different dimensions hence different text alignment.

First Image

Second Image

1
I think you should reconsider your approach. Check out using NSTextAttachment to layout images in your UITextView. See stackoverflow.com/questions/20930462/…TomSwift
Thanks. It worked for me.Shashwat Mittal

1 Answers

0
votes

You have to code some like this example above, for each one object that you wish to align:

    @IBOutlet weak var messageTextView: UITextView!

    var newConstraint = NSLayoutConstraint.constraintsWithVisualFormat("H:[messageTextView]", options: NSLayoutFormatOptions.AlignAllCenterX metrics: nil, views: ["messageTextView": messageTextView])

    messageTextView.addConstraints(newConstraint)