4

I wonder why my textview text didn't show up from starting text. This is the image from my Xcode IB

Image From XCode

When I run it on my iPhone 6 Simulator and others

Simulator

Actually it should start from "Example Notification...."

Please help me out.

Thiha Aung
  • 5,036
  • 8
  • 36
  • 79

4 Answers4

6

Those who didn't start UITextView from start,here is the answer.I am sure it worked 100% on iOS 8 and higher on any devices.

1.You need to deselect these at your view controller where textview is applied

Go to ViewController > Attribute Inspector > Search Extend Edges > Under Top Bars & Under Button Bars

2.Add the following code at your view controller

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    self.yourTextView.setContentOffset(CGPoint.zero, animated: false)
}

Special Thanks to @El Captain

Thiha Aung
  • 5,036
  • 8
  • 36
  • 79
0

To maintain UINavigationBar translucent and allow user to rotate the device while reading UITextView I used something like this:

private var firstLayout = true

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()

    if firstLayout {
        firstLayout = false
        textView.setContentOffset(
            CGPoint(x: 0, y: -topLayoutGuide.length), animated: false)
    }    
}

Tested on iOS 9 and iOS 12 Beta.

0

In my case it was iOS 13. UITextView was constrained to edges. It's content was set on did load, after that text view automatically scrolled to the bottom causing large title to shrink.
What helped me is to wrap setText in to async:

DispatchQueue.main.async { 
    textView.text = logs
}
trickster77777
  • 1,198
  • 2
  • 19
  • 30
0

You can also keep UINavigationBar isTranslucent and UIScrollViewContentInsetAdjustmentAutomatic,

Just to fix the textView is hidden by navigationBar, then add the below code:

- (void)viewDidLayoutSubviews {

    [super viewDidLayoutSubviews];
    [textView setContentOffset:CGPointMake(0, -self.view.layoutMargins.top) animated:NO];
}
yuanjilee
  • 429
  • 5
  • 16