MoZhouqi / KMPlaceholderTextView

A UITextView subclass that adds support for multiline placeholder written in Swift.
MIT License
805 stars 141 forks source link

swift3,xcode8,I use xib to set it but failed,here is the photo,can you tell me why? #35

Closed bianxiang closed 7 years ago

bianxiang commented 8 years ago

I want to set placeholder on top. tv tv2 tv3

philhenson commented 7 years ago

Hey there @bianxiang, I ran into this issue as well when using IB. I noticed the content offset was changing after loading the view. I added the following line to layoutSubviews() in the placeholder view class:

setContentOffset(CGPoint(x: 0, y: 0), animated: false)

So the updated method looks like:

  open override func layoutSubviews() {
    super.layoutSubviews()
    setContentOffset(CGPoint(x: 0, y: 0), animated: false)
    placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2.0
  }

I hope that helps!

MoZhouqi commented 7 years ago

Thanks @bianxiang @PhiltheHen, if the scroll view is the first child view of the view controller's view and the property automaticallyAdjustsScrollViewInsets of the view controller sets to true which can cause the problem.

There are two ways to solve this problem:

  1. Set automaticallyAdjustsScrollViewInsets to false
  2. Avoid the text view to be the first child view of the view controller's view