Horizontally scroll single line UITextView? - ios

I need a view that allows me to have an editable method of text entry that is limited to one line, but can scroll horizontally. After a bit of research, I found that maybe a UITextView would work well.
This is going in a table view cell so I've tried putting this in awakeFromNib()
code.textContainer.maximumNumberOfLines = 1
code.layoutManager.textContainerChangedGeometry(code.textContainer)
but this is what happens (I'm repeating the same line to fill the text view)
So for attributes I need to assign, I need:
Disable Vertical scrolling
Enable Horizontal scrolling
Limit Text View to one line
If anyone also knows a better way to do this (maybe with a scrollable Text Field?) I would love to hear it.
Thanks in advance!

Related

How create a tableView that covers an image when it is scrolled

I'm trying to develop something like CSStickyHeaderFlowLayout but customized for my table, but I'm not sure how can I achieve this goal. The idea is
Someone can give me a hint how achieve this objective?
To add to Vollan's answer, to make the title stay still you could use a view that contains two subviews: the first is the scrollview (with the image and table as Vollan suggests) and then add another view (like a UILabel) for the title. Thus, while the image and table scroll in the scrollview, the title will stay still.
Best solution would be to wrap everything inside an UIScrollView. That will allow you to scroll to bottom of the screen and then only scroll the tableview. That way it will appear like the tableview will overlay the image.
While using a tableview within a scrollview would likely work, your tableview would have to always be it's full size (without some annoying constant re-sizing), so you'll lose the value of the enqueuing/dequeueing that makes tableViews work so well.
The CSStickyHeaderFlowLayout has example pretty similar to what you want to do, did you look at their examples? You may be able to play with it and get it to do what you want If your problem is simply having a constant title, you can just add a view above the table or use the NavBar and adjust the contentInsets
You might also consider using a collectionView instead. It's much more flexible as far as layout goes.

UIViewController with UITableView and TextField storyboard placement

This might be a simple question but using storyboard I can't seem to position my table, a message field and a button correctly. In the picture below, if it's positioned that way, only then do I get to see the text field and button at the bottom of the screen and the table view takes up the rest of the screen. If I drag the text field and button to the bottom and resize the table, the text field and button disappear and the table is cut off. Why is that? Is there a solution to this without doing it programmatically?
Easy solution is to remove all constraints then position them where you want them.
You'll find you get different effect when try to reposition items depending where you drag from for example double tap an item and nudge it with arrow keys or grab the middle to move it resizing via the corners.
But in my opinion it's easier remove all constraints from the view and then set them as you go.
Also you might want to consider using a container view for the table view and have a separate UItableViewController that way you can easily separate out that the tableview logic from the other ViewController. It will help stop things getting a little messy later on as project grows.

iOS: Stop ScrollView from making room when selecting textfield at top

I've scoured through several questions asking about how to prevent scrolling when selecting a first responder however nothing I find seems to work for this issue.
I have a UITextField above my table view at the very top of my page. When the user selects it (or when I do it programmatically) it drops down a bit, seemingly giving room for options such as "paste" or autocorrect (which I've disabled). I'd like to prevent this from happening.
I've tried setting the scroll position myself, which it initially does, but then it instantly jumps down a bit. Is there a way I can make the paste/edit bubble appear below the textfield (like it does with textfields in the header)? I'm thinking perhaps that will prevent it from jumping downwards, but I can't find information on this.
I'm completely stuck so any help is appreciated. Links, vague suggestions, whatever. Thank you.
Try embedding your text field in a scroll view the same size as your text field.
The reason why this should work is because when a text field becomes first responder, it only scrolls the scroll view that is its most recent ancestor in the view hierarchy. If it only finds the dummy scroll view, whose content size should not exceed its bounds size, then no scrolling should occur in either scroll view.

How can I make/program a UIlabel to scroll horizontally upon user input?

I'm making a simple calculator in iOS, and I want the user to be able to scroll the label horizontally when the end gets truncated.
How would I go about doing this? My original idea was to make two buttons that would move the label left or right by using stringpadtoLength type of method, but that seemed inefficient.
I see two ways of building this.
Use a UITextView and always return NO from -textFieldShouldBeginEditing:. This should get you 90% the way there very fast.
Build a custom control using a UIScrollView which contains a UILabel that uses -sizeToFit. This will be a bit more work, but will do exactly what you expect.
I went for Jefferey's second suggestion because I thought it would give a "cleaner" result. Turns out, it's not that easy to implement. Here's what you have to be careful about when you're putting a single-line UILabel inside of UIScrollView, in order to be able to scroll horizontally through the text.
The parent UIViewController should have the box "Adjust scroll view
insets" unchecked. If you forget this your text may be placed below the content of the UIScrollView, meaning that you can only see it if you hold it while over-scrolling down.
Call [self.toolboxItemNameLabel sizeToFit]; in your UIViewController's viewDidLoad in order to set the right size for your UILabel. This ensures that the scrolling is comfortable, going from the left to the right of the text.
When using autolayout, you must add constraints for the leading and trailing space to container of the UILabel which is inside of the UIScrollView. Thanks to this great post for the answer.

UIView position relative to another UIView

I'm trying to create a custom accordion-list. On tap it should expand the tapped line and the next lines should change their position relative to the expanded one. By tapping it again it should contract. By tapping another non-expanded line, the expanded line should contract and the tapped one should expand.
I tried to solve this by using subviews with TapGestureRecognizers. I have a undefined number of lines. On tap I change the height of the tapped line and rearrange the position of the following lines manually. Now, it's getting really confusing to handle all possibilities of expanding/contraction/positioning. I'm looking for a more comfortable way to handle this.
Is there any way to align the subviews vertically so that the positions of the lines change automatically if one height changes?
I think a better solution is to use the tableView where the cells will contribute your custom view.Positioning and all will be handled by tableview itself.
If you are working with iOS 6, this should be pretty easy with constraints. Specify that each view is to be located a certain distance from the bottom of the one above it, and when the ones above it move or expand or contract, that constraint should force everything else to move to keep the gap you specified.
EDIT: I just realized that you mentioned in your OP that you may not know for sure how many views you are going to need ahead of time. That probably makes the table view method others have suggested more favorable. It is still possible to do with constraints though (and I found a pretty detailed tutorial here that goes over everything).

Resources