How to insert UIImageView in UITextView in the same way that iphone default message (SMS) app uses to insert multimedia content in the UITextView

后端 未结 4 1178
Happy的楠姐
Happy的楠姐 2021-01-18 21:16

I want to insert UIImageView in UITextView of Toolbar having send and camera button in the same way as iPhone default SMS app do.

4条回答
  •  梦谈多话
    2021-01-18 21:29

    You would be better off using a UIScrollView and managing UITextViews and UIImageViews in it. UITextView doesn't support adding image inline with text. In fact, it doesn't really support anything other than multiline text.

    Per your comment below, there are three things I can think of to get the image as part of the text entry box:

    1. They're not using a UITextView, but instead some custom view. That sort of thing is difficult to replicate.
    2. They are overlaying a UIImageView over the UITextView as a subview and setting the contentInset of the UITextView so there is no overlap.
    3. They are using a separate UIView to contain both the UITextView and UIImageView as subviews and simply arrange those subviews as needed.

    Both 2 & 3 are very similar (just slightly different approaches) and probably your best approach. Personally, I think 3 is probably the best, since it give you the most control over the position of both views, but 2 should also work fine.

提交回复
热议问题