Thiha Aung
Thiha Aung

Reputation: 5106

Why my UITextView text is not show from starting and hide under Navigation Bar

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.

Upvotes: 4

Views: 3267

Answers (4)

yuanjilee
yuanjilee

Reputation: 607

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];
}

Upvotes: 0

trickster77777
trickster77777

Reputation: 1218

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
}

Upvotes: 0

Pawel Sledzikowski
Pawel Sledzikowski

Reputation: 149

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.

Upvotes: 0

Thiha Aung
Thiha Aung

Reputation: 5106

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

Upvotes: 6

Related Questions