UITextView places text lower than I want it to be - ios

I got UITextView with some text. Text always appears not in the upper left corner of the text view but with a large indent from upper border like this:
textView with text
I set attribute "content mode" to "Top left" like this but it did not helped:
attribute setted to top left
Method [self.infoTextView scrollRangeToVisible:NSMakeRange(0, 0)]; didn't helped.
Method [self.infoTextView setContentOffset:CGPointZero animated:NO]; can do the job BUT it moves text only if it is already visible to user so it creates a mess in a UI (First user sees text at the bottom and then text instantly changes position).
How do i place a text in the top left corner of UITextView before it appears on screen? Will appreciate any help, thanks in advance!
BTW I am using Xcode version 8.2.1.

Solution: I added fresh new textView and it's content was exactly in the top left corner. I am sure that i did nothing with textView in my code and in storyboard file. I saw this bug in more than one of my projects but previous time adding fresh new textView did not solve the problem. This time - it helped. Thanks for your answers!

Related

Textfield Connecting and Labels

I have always had this problem and could never figure out how to solve it. My issue is that I want to produce a similar thing as the photo: Image
I want to be able to have text fields connect like this and be able to have a 'label' on the left while still being able to input on the right. Any help is greatly appreciated.
If I am not mistaken, I think that what you want is to have a label on the left and a textview on the right. The image you have supplied looks like the textViews and labels reside within a UITableView controller as static cells. What they have most likely have done here is simply extended the label from the left to the centre and the textview from the right to the centre, such that each takes up half the cell (and added constraints). Then you can set the text alignment to left for the label and right for the textview. The final thing you should do is get rid of the border of the textview, which can be found in the attributes inspector and is called Border Style. You want to set it to the far left option, like this:
As the background of the cell is white and the textview's also, you shouldn't need to change it, but if you do there is an attribute for that a bit further down that you can have a play with.

Adding Spacing Constraints to Text Field

I have a simple storyboard with a text field. I want to add spacing constraints to this text field so that, when I rotate the device, the text field will auto stretch across the screen instead of stopping halfway.
I have looked at multiple tutorials and they all say to "Control-drag from the text field toward the top of the scene, ending in the empty space around the text field. This should reveal a pop-up menu from which you can edit the spacing constrains of the text field."
However, when I control-drag from the text field, I get this different pop-up menu:
This other pop-menu clearly does not allow me to do anything with spacing constraints. In fact, I can't click on it at all.
Furthermore, clicking "Editor > Resolve Auto Layout Issues" does not work, as the entire sub-menu is grayed out.
How can I correctly add a spacing constraint to this text field so that when I rotate the device the text field will correctly fill up the screen? Please try to refrain from answers that involve editing code, as I don't actually know any Objective-C and would like to make this effect in the storyboard.
NB - If it is at all helpful, I am following this tutorial. Albeit it is with Xcode 5, other tutorials on Xcode 6 suggest the same pop-up menu should exist.
You probably didn't activate auto-layout in the first place. Check the option in the right panel, under the File section:
It's a new behavior of IB
For example:
Now the contents of the menu depend on the edge of where you are trying to tie constraint:
or simple use tree from left of IB
Open the document outline to see the view hierarchy and try control dragging the text field to the View, it should show the options there. Your menu appears when you control drag onto the View Controller.

Why is my text view full of unwanted space? Extra lines not in code. Screenshots

I have a programatically populated storyboard text view.
[textView setFont:[UIFont boldSystemFontOfSize:11.0f]];
textView.text = #"Why oh why is this happening to me?! This seems like a pretty absurd problem to be having.";
This is how the text box loads. The text box is created between the image you see at the top and the two images you see at the bottom and it fills the whole space in-between.
How the text box looks if I scroll up (and how I want it to appear). It seems like there are a bunch of unwanted lines populating the text box before my text?!
So I have tried fixing the height and width of the text box using constraints, I have tried stopping the view scrolling and I have tried setting the content insert parameter of the text box. None of these things helped.
Anyone got any suggestions as to why this is happening?
I'm not sure if this is related, but the only change to this view controller recently has been making the navigation bar translucent.
See this question and answer
You need to select the parent view controller and unselect the 'Adjust Scroll View Insets'
:o)

Weird UITextField glitch / bug: Cursor jumps left when centered text is deleted

I have a weird glitch that occurs when I press the delete key in an empty UITextField.
I shouldn't be able to delete anything but the cursor moves over to the left about a tab width in the text field when I hit delete and it is empty.
This only happens when I have the text centered in the text field, not when it is left justified.
When I resume typing it jumps back to the center and behaves normally.
Any idea what could be going on?
In 2018 on XCode 9.3, and IOS 10.3...
I have verified that... at least in my case, the problem was being caused by the text field containing placeholder text.
When I removed the placeholder text, the cursor behaved "normally" / as expected.
Even though this isn't a very popular question, I just created an account to share my discovery regarding this problem.
The glitch/bug you're experiencing is caused by one line of code that you have (probably) added to your UITextField. No, it is not due to your UITextField containing a placeholder like the other answer suggested.
To fix this problem, the line you'll need to remove is
textField.clearButtonMode = UITextFieldViewModeWhileEditing
Adding this line adds a clear button to the right side of your UITextField while it is being edited.
This causes your text to be shifted left by the size of the clear button, but only when the button is there (in this case, only while editing). This is why you may notice your text shifting back into the correct position when you have finished editing.
Hope this helps someone down the road!

UIPopOver, UITextView and automatic resizing

I've got an app where I allow the user to add events to a list. The method I use to do this is via a form that I show the user in a UIPopOver.
The form has the following components (in this order, top to bottom):
Event Description Label (UILabel)
Event Description (UITextField)
Event Details Label (UILabel)
Event Details (UITextView)
Event Time Label (UILabel)
Event Time (UIDatePicker)
Save Event (Custom Button)
Cancel (Custom Button)
I'd prefer not to show a screen shot since it's a sensitive app. :-)
So........
All is well when I first show the UIPopOver. Everything appears as I wish. The overall layout is about 650 pixels tall, which is just tall enough to take up pretty much the whole screen (vertically) when in landscape mode.
When the user tries to interact with the `UIDatePicker`, everything goes swimmingly (well).
When the user taps into the Event Description (`UITextField`) field, the keyboard appears and the `UIPopOver` shrinks so that basically the `UIDatePicker` and buttons are hidden. I consider this OK, since they re-appear when the keyboard is dismissed.
The problem I am having is when the user tries to interact with the `UITextView`:
When the view of the `UIPopOver` has its `backgroundColor` property set to `[UIColor whiteColor]`, the `UITextView` initially appears with a thin black border. I like this.
When the user taps in the `UITextView` to begin editing, the `UIPopOver` resizes to accommodate the keyboard and, during the transition, the black border "shrinks up" and disappears. This is in spite of my shocks and struts being set so that all dimensions/directions are fixed and it is "glued" to the top-left.
Following this, when the user dismisses the keyboard, the border sort of restores itself to its previous position, but it now adds a thick black border on the bottom that completely obscures the label placed between the `UITextView` and the `UIDatePicker`.
When I change the background of the view of the `UIPopOver` to "`ScrollView` Textured Background Color", the border "disappearing trick" is at least less noticeable, but the black border at the bottom (following keyboard dismissal) is still present.
Questions
Has anyone encountered something like this before?
Does anyone think it's just an IB error and that I need to re-build my XIB?
Anybody got any other ideas? Googling for this issue came up fairly empty for me. If you think of better terms and find something, please let me know (gently).
Boy, I'm a stupid stupid!!! It turns out I had forgotten that I placed the UITextView inside of a UIView (inset 1 pixel on all sides) and set the background of the UIView to be black so that I could get a border effect on the UITextView. Once I remembered that, setting the shocks/struts of THAT UIView turned out to be the solution.
Sorry for wasting your time!

Resources