iPhone UITextView leaves room for 2 lines at the bottom - iphone

When I start typing text in a default textView in my viewcontroller, it's not going to the bottom of the textfield. It leaves room for 2 more lines of text and then starts scrolling.
I want it to start scrolling when I start going beyond the last line.
I tried everything, and I don't know what I can do?
Anyone any ideas?

as UITextView is a subclass of UIScrollView, look at UIScrollVIew's properties, like contentInset and others to see if they might be creating a gap between your frame/bounds and the content inside.

Just adding to what mahboudz already said. Here's some sample code that can be adjusted to get what you need:
UIEdgeInsets contentInset = notes.contentInset;
contentInset.bottom = 10.0;
notes.contentInset = contentInset;
Where notes in this example is the UITextView.

In addition to what mahboudz and Aaron said, I can confirm that UITextView does add some contentInset to the bottom, so I put the following code inside textView:shouldChangeTextInRange:replacementText: of UITextViewDelegate
textView.contentInset = UIEdgeInsetsMake(0, 0, 5, 0);

When moving code from a nib to setting it up programmatically, I ran into a similar problem--wherever the insertion point was, it was scrolled up out of view. I eventually found that my UITextView had a bottom inset of 32 pixels when I created it programmatically, though I'm not sure why. So I fixed it by setting the contentInset when I create the text view:
textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

Related

UITableView scrollIndicator position incorrect

So I have a UITableView. Its dataSource is an NSArray of custom objects beeing loaded after a search. When I scroll to bottom, everything works fine, the scrollIndicator scrolls to bottom as desired.
Now when I scroll back to top the scrollIndicator stops about 50pixel below my UINavigationbar.
I have no idea why this behaviour occurs only in this tableViewController, since my UITabBarController consists of 5 UITableViewcontrollers each inheriting from the same super class.
Any help is appreciated, thanks in advance :)
EDIT:
Putting the following code in viewWillAppear:
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 0, 0);
Solved the issue. Although I still don't know why this issue only occurs in one of the five tableViewControllers...
It looks like you might have set the scrollIndicatorInsets property of the scroll view wrongly. It might be the same for both bottom and top. Set it so that that you only have the margin for bottom.
i.e
use UIEdgeInsetMake( <top> , <left>,<bottom>,<right>); for this. i.e for your case
yourScrollView.scrollIndicatorInsets = UIEdgeInsetMake(0, 0,bottomInset,0); //Here bottom inset would be the value you have right now .
As UITableView's superclass is UIScrollView, its better to set UIScrollView's scrollIndicatorInsets property to required position.

Text cut off in UitextView? How to scroll text page by page properly

I am trying to scroll text in UITextView manually up and down with the help of uibuttons.
This is how I am doing.
[storyTextView setContentOffset:CGPointMake(storyTextView.contentOffset.x, scrollPoint-scrollFraction) animated:NO];
Where
scrollPoint=storyTextView.frame.size.height;
When I scroll up or down, text goes cut off.
See this image:
A UITextView clips it's subviews by default, so either you resize your UITextView to fill as much as you want, or you uncheck "Clip Subviews" in your xib, or with code
[storyTextView setClipsToBounds:NO];
Try this
[storyTextView setContentInset:UIEdgeInsetsMake(5, 0, 5, 0)];
Ok the problem is like this.Your font size is large and mathematically you are setting up the content offset but only depends on the textview frame not the contents height.
Solution is to find out a proper algorithm to get the contents properly visible and then apply the content offset and then move with that specific height such that the text appears correctly.

UITableView not scrolling to the bottom

I have a UITableView (on a UIViewController) on which I want to ad an iAd banner on the top, but below a toolBar I already have on the top. I'm trying to shift the the tableView (in reference to the view) so I can locate the banner in the space left blank.
To check it ou, I create an action in which I shift the tableView frame:
-(IBAction)iAdAction:(id)sender{
self.tableViewConc.frame=CGRectMake(0, 94, 320, 367);}
where 94 is the summ of 44 from the toolbar and the 50 from the banner.
The action works correctly but then, I cannot scroll to the bottom of the tableView, when I try it, it bounces back. I've tried to change the height of the tableView in the same action ( 430 instead of 367, for instance) but it doesn't work. I've also tried it on IB, but it doesn't work either.
I feel that I'm missing something but I cannot remember what.
Any help?
Thanks in advance!
Not being able to scroll to the bottom of the tableview is usually a symptom of its height being too large. (i.e. it's cut off at the bottom)
Don't compute the height you need and put those numbers in your code. Just find out what it should be from the view hierarchy. For example, you might compute the height of your table view with CGRectGetHeight(self.view.bounds) - CGRectGetMaxY(self.iAdView), and the view's y origin with CGRectGetMaxY(self.iAdView) assuming that the iAd view and your table view are both subviews of self.view. Or, even better, just use autoresize masks or autolayout to keep the table view the right size.
You can try
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
I just had this embarrassing scenario where my UITableView would "bounce" but it wouldn't scroll to the bottom. For ME, the problem was that I was dynamically setting the row heights, and my very last cell was getting calculated with a cell height of -115 (yes, negative). Once I fixed that to return a positive number, my scrolling worked just fine.
Even we can achieve the same in storyboard.
Select tableView --> from the storyboard control click on 'add Missing constraints'. That will add the constraint to tableView and View.
That helped me to resolve this issue. Screenshot_Link
Check the number of the row that you can't see.
After in your viewDidLoad, add this method:
myTableView.contentInset = UIEdgeInsets(top: 0,left: 0,bottom: yourCellHeight * rowHeight,right: 0)
I hope I have been helpful

iOS - UITextView doesn't draw text?

I have a UITextView on the screen.
This UITextView is covered by a UIView.
When I set the text for this UITextView, if the textView is not visible (UIView is covering it), it doesn't draw the text.
So when I remove the view that is covering my textView there is no text in my textView. If I try scrolling the textview the text will appear suddenly.
any way to force the UITextView to draw the text at all times? (This only happens when I have too much text in it (about 1000 characters))
I tried calling [textView setNeedsDisplay], before and after setting 'text' and it didn't fix the problem
I have the same problem, my UITextView does not draw text until I try scrolling it or its parent. [textView setNeedsDisplay] does not work for me. Finally, I increase textView 1px and the problem's gone.
CGRect frame = textView.frame;
frame.size.height += 1;
textView.frame = frame;
I know this method is ugly but it does work.
Most things in the system will not display when hidden, which would be a waste of resources.
The correct approach is to call setNeedsDisplay: on the UITextView AFTER it has been un-hidden, then it should draw immediatley.
The limit to the number of characters in a UITextView seems to be around relatively low (see the post here).
The poster in the link I posted suggests putting your content into a UIWebView, which can handle a large amount of text.
Same problem. We have a textview that is configured and put into the view while hidden or offscreen. Most likely due to Apple optimizing UITextView so that it doesn't do layout and drawing unless it is onscreen and visible.
Calling setNeedsDisplay doesn't work because of the optimizations. setNeedsDisplay gets called quite often, so imagine a UITextView doing layout and drawing quite often? Thus the solution above is ugly but works: add a pixel to the frame which will trigger the UITextView to re-layout and redraw. We went with this solution.
Since UITextView is a subclass of UIScrollView, I did something like this:
CGPoint offset = self.textView.contentOffset;
offset.y++;
[self.textView setContentOffset:offset];
offset.y--;
[self.textView setContentOffset:offset];
the same as #Tùng Đỗ without changing the frame... still looks ugly.

Is there a way to put UITextView's scroll indicator to outside UITextView?

It might be a silly question.
I'm trying to set left/right margins like the attached picture. I succeeded to implement it by adding UITextView to UIScrollView.
However, I could achieve almost everything I want with UITextView alone. For example, with UIScrollView, when I manually change the text of UITextView, it automatically scrolls to bottom regardless of setting its .scrollEnabled to No.
It would be perfect if a scroll indicator of UITextView appears outside UITextView.
In the attached picture, let's say the red box represents the entire UITextView. I tried to change UITextView's scrollIndicatorInsets property, but a scroll indicator can be moved only inward to be visible.
Several apps such as Pages, aWriter, Plaintext achieve this feature.
Could you give any suggestion?
Thank you!
I
You can set the scroller right inset value of the UITextView to negative value and disable the clip subview option to achieve your require. No other scrollview is needed.
Alternatively you could set the Right contentInset property.
UIEdgeInsets insets = textView.scrollIndicatorInsets;
insets.right += 5; //add what ever is your margain
textView.scrollIndicatorInsets = insets;