Sliding Text In a Label - ios

In my Xcode Project I have a tableview that is populated with a label. Sometimes the text in the label does not fit all the way causing the label to cut off the rest of the text. So I will like to add in a sliding effect in the label where it will show the beginning text and then start to slide all the way to the end of the string and back only when the user is not scrolling in the tableview. How will I implement this?

Just assign the leading, trailing, top, bottom constrains of this label = 0 with the cell itself and let the tableView to calculate each cell's size dynamically

Related

Two stacked dynamic height labels in UITableViewCell

I am trying to have two labels stacked in a UITableViewCell. I have AutomaticDimension and estimatedRowHeight set on my tableView.
I want the cells to show up stacked, with their dynamic heights if they both have content.
If only one has content, I would like it to be centered in the cell, or rather have the cell collapse to only show that label.
I have tried every constraint combo I can think of, but usually the labels either do not expand, or I end up with filler space where the label should be.
If the label has no text, I am setting label.text = "".
I am calling sizeToFit() on the labels each time I set the text.
What is the correct constraint combo? Here is what I currently have to start with.
you have to make two labels with leading, trailing, top and bottom constrains and don't add height constrains
make the number of lines for labels = 0
check the title label and from size inspector menu click on the vertical content hugging priority to be 250 not 251 as shown in the screen
image
in the viewController connect your tableview and add these lines
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 44
This could be done using StackViews in iOS,
in the Storyboard Select your both Labels and embed them inside a UIStackView
one of the benefits if you declared a good constraints it should automatically handle the requested behavior.
I recommend this tutorial to get started with UIStackView here
Better solution is UIStackView.
If still you want to go with UILabel you can try one more thing:
Setting label.text = "" will decrease the height of label but the constraint for distance between the labels will not make the label in centre.
For that add a referencing outlet of distance constraint and set it :
distanceConstraint.constant = 0
programatically while setting the label.text = "".
This will set the label with data in centre.
Hope this helps.

How to set labels text align to top UITableViewCell in iOS

I have tableViewCell which contain two labels with title and subtitle .Both have numberOfLine 0 with sizeToFit in cell class.But if text of one them is less then label text with less one, comes at center as
Cell height is base on Label text size and if both Label text have same number of line then it appear good . So i want text of both label align to top.Cell height should be base of text of Label with more number of line.
This can be achieved in auto layout by setting the bottom labels constraint to >= rather than just = to the bottom of the cell in the xib. That way it should automatically fill the least amount of space so that text vertical alignment is no longer an issue.

Is it possible to get part of tableview cell to disappear by reducing it height at tableview delegates

I have a table view cell which has three elements vertically
a title label
a text box
a validation label
I want to show validation label only when it fails.
If I just hide the validation label then the space occupied by the label is stil there and it looks awkward having more distance between the next row
so what would be the best approach to handle the scenario
Change the table-row height whenever validation label's hidden status changes
I think this approach probably will not work because label is still there in the tableview cell so the tableview cell will readjust itself to have the label height there irrespetive of whether it appears or not
Change the label height constraint constant and tablerow height whenever there is change in label's hidden status
so basically if I want to hide it then I will be setting the label's heigh to zero and readjust the tablerow height ... it'll work but there is a problem..
If I set label number of lines zero then depending on the content label will change its content height .... but as I am using constraint for height... I will be hardcoding the height and it can lead to problem again.
Basicallyy my need is I have one label and text box whose height is fixed and I have a one more label ... this could be hidden sometimes and this could be one line or 4 lines
I want the row height to adjust according to that(0 lines(hidden),1/2/3 line label visible)
sometime even the first label that I was talking it could go to the next line in smaller devices like iphone 4s
so somebody help me out on the issue

Move element when UITextView expands

I am trying to make a TextView in my scrollview look like the "Hoshi" TextField in this github repo raulriera TextFieldEffects
If I only have a textview with top/left/right constraint it will expand when I enter more text which is right.
But when I add a UIView under it, it will cut off the text if I enter alot of characters, what I want to do is to move the view/line under it along with the textview when it expands.
My constrains for the UIView is top space to textview >= 10 I thought that would move the View when the textview expands but nothing happens, instead the text gets cut off and the view wont move
Here is a image for the constraint:
So how can I make the view move once the textview expands?
Programmatically change the height constraint of the textview based on the text entered.
Remove the bottom constraints of the lable it will work as desired.That bottom constraints don't allow your lable to move down as your textView height increases.
I found a solution.
I had to set the UIView's bottom constraint to be >= low priority (250). That would make it expand together with the textview

Set constraint for textview to the right of cell

I have got a UITableView with dynamic cells.
In each cell will be a small textview on the right side of the cell.
How can i set an constraint, which fixed this textview with a fix value of space to the right side of the cell in iOS8 Swift?
At the moment I only know, how I can set the space from textview to the left side of the cell, but I need to fix the space between textview and right side.
You can create a custom TableViewCell or in your prototype add the textview and manipulate the constraints of XIB file in storyboard. What you can do is set for example the constraints of width and height and also set the Spacing to the right side and the top side.
Or, another thing you can do is: choose the textView and then press ctrl+LeftMouseClick and drug to the left into the cellView.Like this:
When you let the click choose "Center Vertically in Container" like this:
To "Center Horizontally in Container" do the same thing as above, but this time drug to the top, int o the container cellView again.

Resources