Label Text middle truncate - iphone

I have taken a custom tableViewCell with 2 labels .if the text in the second label exceeds i am showing the text in the second label with middle truncation. when the user clicks on the truncated text cell i need to pop up an alert with the complete text . any idea how to find the cell which contains the truncated text .

a lable is truncuated when it's size become greater than fram width. you can find both these by using
lable.frame.size.width
and NSString sizeWithFont method. compare then and found if your size of lable is greater than width. enjoy :)

as you uses a custom tableviewcell just give your labels tag values and at the time of cell click just find out both the labels using the tag values and do what you need to do ie show whole text to user in alert view

Related

Dynamically update height of collection view cells

I have a collection view with many different cells in it. Each cell takes up half the width of a page, and contains an image and a label under the image.
I am starting with all of the labels being truncated, along with a "Read More" button that is supposed to expand the label.
The code to do the expanding is working, but the problem is that if I click the button on a cell in the top row, and the 2nd row also has 2 cells in it, I need those 2 cells to move down the page when I click the button as well. Right now, the text is technically "expanding" but then just being truncated due to having no height left.
I believe I need some sort of invalideLayout combination with something else to make this happen, but I can't seem to piece together how I would force all of the cells to move downwards as well.
The "Read More" button is attached to a function call that updates the number of lines for that text from "3" to "0" and reloads that cell.
Thanks in advance!

Devide text to UITextViews

I have long text and 2 textViews.
I need to insert this text to 2 textViews(they have no scrolling).
It's like book pages(first page is a one textView, second page is a another textView).
So, question is: how to determine which text length I need insert to first textView?
You can set the complete text to the first textView, calculate the visible text range and set the remaining text to the second textView. An alternative is to manually calculate the range of the text that will be visible in the first textView, however it requires ugly recursion with sizeWithFont that i can't believe is so fast, i'd follow the first way.
See this answer to learn how to get the visible text range.
First figure out length of each line, font, and how many lines you can fill into the each textview. Use following to do this
CGFloat stringWidth = [text sizeWithFont:[UIFont fontWithName:your_textview_font_name size:your_textview_font_size]].width;
Then use substrings operation.
Shouldn't be difficult to do this!

UITableView cell text is cut off

I am having a problem with the UITableview cell cutting off strings whose characters are more than 12 chars. Any ideas why this would occur? I have not made a custom cell at all. I cannot find any solution to this problem through a Google search. Any ideas?
You should be able to set the label properties to re-size the font based on the label's contents using adjustsFontSizeToFitWidth. This will essentially decrease the font size to make the text fit all on one line.
Your cell likely contains a label, which in turn is set to given bounds. What you need to do is ensure that your label is the same size as your longest string, or bigger than it.

Creating a fixed formatted cell in UITableview

I want to have a tableview create rows that look like this:
value1 item1 container1
value10 item10 container10
value100 item100 container100
value2 item2 container2
What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.
I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.
You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)
Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.
There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.
It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.
Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.
You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.

Break a text in a label in iphone

I am new to iphone development.I have created three labels in a cell and i have just displayed the text in the corresponding labels , but i want to display the full text in the label.I am not able to see the full text,So is there any possibility for breaking the text and show them in two lines.I am not displaying any static text .I am getting the text dynamically from the website and displaying it in the label.Please help me out.Thanks.
set label's numberOfLines property to 2 (or to 0 to have any number of lines you need)
set label's lineBreakMode property (e.g. to UILineBreakModeWordWrap)
make sure that label's height is enough to contain 2 (or more) lines of text