How to shift drawn text to top on UIView? - ios

I am drawing text on a UIView using core graphics, the restriction with this is that when the UIView is fully drawn to the end i can't shift all drawn text above to create empty line at the bottom to draw new text. I don't want to use the UITextView and UITableView.
A visual explanation:
Suppose a have a view as below to draw the text-
So I am on the last line in this view and when this line is completely filled, I have to shift to one line below which is not there. What I want to do is to shift the whole screen text one line up (shifting out the first line from screen), to make space for new line.
This view is actually a larger one to provide scroll back, but to explain the situation I just mentioned so.
Is there any way to do so? Please suggest.

If you want to provide scroll back, it means that you don't want to shift the whole text up to make space for one more line. Because in doing so you will lose the first line.
What you need to do is resize the view and make it bigger, this way you have more space to draw some more lines.
I would advise you to use a UITableView instead. It's too much work to draw the text by yourself and provide scrolling and all for no apparent advantage. Maybe just so you can learn how to do it :)

Related

iOS: How to display a box of 'tappable tags'

My use-case is like this:
The user defined some tags (text like "#asdf", "#qwerty", "#let_me_think_about_it" and "#decide later"). I want to display these in a box without scrolling (and don't know, how many tags the user created until I display the box).
The box itself should not be scrollable at all but be shown in a UITableViewCell (which is being scrolled). So it must compute the proposed height and respond to Autolayout mechanisms. If a (ARM) Mac user resizes the window to be smaller than before (or an iOS user rotates the device), the box should increase/decrease its height, as necessary (within the limits of Autolayout, since I know of some issues). Each of the tags should be (de)selectable at the same time (UILabel with UITapGestureRegognizer attachted?) and be able to displayed 'selected' (via a background view).
So, the box should primary try to align all content horizontal. If There's not enough horizontal space, do a "line break" and continue on the next "line".
My current solution is a UIScrollView that the user can scroll horizontal and tap any of the (UILabel) views. The displayed views itself are being loaded from a NIB file, like a UITableView does. The issue here is that not any of the selected tags might be visible at the first glance.
If there was no Autolayout, I'd exactly know what to do. But since there it is, I want to use Autolayout in my NIB files and wonder what you would do?
(How do you compute the required width of such a view and decide when a line break is to be done (and how?))
I think I need a simple hint. But if it needs code to explain, ObjC and Swift is both acceptable. :-)
So, the box should primary try to align all content horizontal. If There's not enough horizontal space, do a "line break" and continue on the next "line".
This sounds like a job for UICollectionView with UICollectionViewFlowLayout. You can disable scrolling, and the layout object will tell you the size of the content so that you can adjust the size of the box.
(How do you compute the required width of such a view and decide when a line break is to be done (and how?))
If you're doing it yourself, you add up the widths of all the items on the first line, and if it's larger than the available space, you move the item that extends past the limit and any subsequent items to the next line. Repeat as needed. But that's exactly what a flow layout does for a collection view, so there's no need to roll your own.

How do I create an UIImageView with a diagonal Cut?

I have an app with an imageView that needs to have a diagonal cut. Here is a picture for reference I am not sure how to code this. I suspect a mask is needed, but not sure.
So upon further examination and some thought I realized that all I needed was to draw a line in between the two views. Then I can just have the line move with the text view as it scrolls.

Horizontally scroll single line UITextView?

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!

iOS - how to handle a case when there is a long text area in an app screen?

I am having a usability issue where in an app screen, there may be too much text and I have nowhere to put that text.
I am attaching a screen shot of my screen. You see how the text on top has more text, but there is no room to put that text. So the text just ends in ....
What is the common way people handle this kind of a situation?
Thanks!
Redesign your UI so you have more room for that text. Maybe your content will need to scroll. You will need to change that label so that the max number of lines is greater (or 0 for unlimited), and make the frame larger to accomodate more lines. You can also reduce the font size a little to decrease how much extra space you'll need to give it.
If you really wanted to, you could use a UITextView for that text, which allows the text to scroll easily (it's a UIScrollView subclass). Then you could just scroll that text, though it wouldn't be very good UI and you would still want it to be more than one line, because scrolling when only one line is visible at a time would make it hard to read.

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