UITextView horizontal scrolling - uitableview

I have a UITextView which wrapping words of long text and it have a vertical scrolling functionality.
How can I switch off the word wrap, and switch on the horizontal scrolling with keep the vertical scrolling?

i have seen this answer in stackoverflow only..
Let's say I want a scrollable width of 600 and a visible width of 250.
The first step is to make the UITextView a wide as the area you want to be scrollable. So what you would have put into contentSize, in this case 600.
Then the right inset is set to the difference between the actual width and the width you wanted. In this case 350.
This way cursor is restrained to the width you need BUT there is text visible to the right of your desired width, after all, the UITextView IS 600 pixels wide.
Now here's where the really hackish bit comes in, don't read on if you're sensitive or have a weak stomach.
Get an image of the user interface to the right where UITextView should end. Insert it into the NIB as an UIImage view and put it back in it's place, making sure that it's on top of the UITextView.
When the view is displayed, the cutout sits on top of the UITextView and hides the text overrun.

Related

Truncate UILabel before it runs into another UILabel dynamically

Basically, I have this situation:
Two UILabels in a UITableViewCell. They're both constrained to the top of the cell. One is constrained to the left of the cell, and one is constrained to the right of the cell.
There exists a change that the UILabel on the left can run into the UILabel on the right. Is there anyway to truncate the text x points before it gets to the UILabel on the right?
Right now, I handle this by giving the UILabel on the left an explicit width that ensures it will truncate before reaching the UILabel, but the explicit width is not dynamic based on screen size. If there is a larger screen size, it might not need to be truncated. I'm new to iOS development and am not sure how to do this.
The best way to achieve this is in auto-layout. Make sure the label on the right is a fixed size, you can even change it programatically if you need to accommodate to screen size. But the thing is this one needs a width constraint. The label on the left does not have a width constraint, instead do a horizontal spacing in front of it to the cell border and from it's trailing end to the start of the label view on the right. It will widen and shrink to fit the size that's left for it.

UITextView Line break mode for new lines

I am working on an UITextView where I have many lines. The width of lines is less than the width of uitextview frame width.
I want to display ellipses when there are multiple lines which are not visible (because of uitextview height is less ) instead of showing scroll bar (I am not showing the scroll bar because the user doesnt want to see the scroller in that textview).
I have used lineBreakMode property but that does work only in one line.

Align UILabel Text to bottom left corner

I have a UILabel that is positioned on top of a UIImageView. The text can be various lengths, so it is necessary that I make the label as large as possible (The same size frame as the imageView). The problem is, I don't want the text from the label to cover the image by being directly in the center of the image. It's easy to set left alignment in a UILabel. Any clue how to set vertical alignment as well? Basically I want the text to hug the bottom left corner no matter what length it is without being cut off.
You can accomplish this with Autolayout. If you set up your constraints so that the label is fixed to the bottom left, but don't set a height constraint, Autolayout will use the label's Intrinsic Content Size. This just means that as the label gets more text / changes font / etc, the label will grow in height and will only ever be tall enough to contain all the text in the label.

Scrolling in TextView

I have a UITextView with Scrolling Enabled.
My problem is that the TextView is small, width for two lines, adding successive lines the scroll does not appear to move around the TextView.
In short, I need to know how to implement the "scroll" according to the TextView grows.
Thank you!
If there are more content in text view with respect to size of text view then by
yourTextView.scrollEnabled = YES;
will scroll add the scrolling behaviour in your text view.
But if your text view's content is equal or less than to your text view's size then there is no need to scroll the text.
By default the TextView scrolls in vertical direction. So, when your content inside TextView will become more than its frame.height, it will automatically allow you to scroll vertically.

How to shrink height of UILabels if needed via Auto Layout

I have several UILabels laid out on my View Controller. While working in Portrait mode, I have increased the height of each label so that the boundaries are all touching - they're stacked on top of each other without any spacing in-between. I have a big title and button located at the top and bottom. I have already fixed the top title to always be centered at the top, and the bottom button fixed to the bottom. I also have fixed the middle label to be vertically and horizontally centered in the view. That's all working great. My problem is, I can't seem to figure out how to get the labels to all fit on screen and mostly vertical centered collectively when the height is reduced. I would like it to reduce the height of each label as needed (but not too short such that the text is clipped). I've tried pinning the heights and then changing them to less than or equal to, but in doing so it wants to update the frame to remove the extra height, causing the buttons to no longer be stacked right on top of each other. Then if I set vertical spacing constraints, it will be fixed so it will result in the labels too close together in Portrait if I use the standard value, or if I go with a fixed number they won't adjust to fit in Landscape.
What do I need to do in order to have the labels expanded to fill most of the view when in Portrait, shrink a bit on a 3.5" screen, then really shrink when in Landscape? The labels should all be centered collectively, based off that middle label that's always centered. This is basically what I'd like to obtain:
What you want to do is set the label's heights to be equal to one another. Then provide constraints for distances between each label, and between L/R sides and top/bottom sides. This way, the labels will shrink when the screen height shrinks.

Resources