UITextView textContainer exclusion path fails if full width and positioned at top of textContainer

后端 未结 5 1345
余生分开走
余生分开走 2021-01-01 22:46

In iOS 8, I\'m trying to add a UIImageView as a subview of a UITextView, similar to what\'s shown here - but with the text below the image.

5条回答
  •  攒了一身酷
    2021-01-01 23:24

    I tried too hard toying with exclusion path.

    My problem was that top level exclusion path never worked, it pushed content towards the top instead of center, while bottom content had double the exclusion path margin.

    Here is what worked for me:

    1. Override UITextView
    2. Init it with your textcontainer by putting this inside init:

      super.init(frame: frame, textContainer: textContainer)

    3. As per Daniel's answer, put inside layoutSubviews:

      self.textContainerInset = UIEdgeInsets.init(top: t, left: l, bottom: b, right: r)

    4. Inside your UITextView subclass init() or in storyboard, disable scrolling.

      self.isScrollEnabled = false

    For more details, read this super-helpful thread.

提交回复
热议问题