How to display dots in place of long text in UITableViewCell - iphone

I have a table view with 2 rows.
in these rows in detail TextLabel i have long text i didn't want to display all the text but
I need to display dots for last characters if it is a long text
for ex:
text in cell.detailTextLabel is :'DATABASE Entered in to the cell'
I want like as : 'DATA BASE Ente.......'
How it is possible?

use label to display and set the property like
cell.textLabel.lineBreakMode = UILineBreakModeTailTruncation;
cell.textLabel.numberOfLines = 1;

dot will come automatically.
if your text is big compre to label size. then dot will come automatically.
ya you have to fix size of font.

You can set the property of UILabel:
#property(nonatomic) UILineBreakMode lineBreakMode

Set lineBreakMode of UILabel to UILineBreakModeTailTruncation, but it's the default value already. :-)

Try setting adjustFontSizeToFitWidth to NO and set lineBreakMode to UILineBreakModeTailTruncation

Related

how to consume string from middle and show in UILabel

I have an String that is "WAKEFIELD - TRINITYIGINY - (3.15 miles)" that need to display like this in a UILabel.That means char is consume from middle.
Note that,it should be dynamic and need to display into UITableViewCell.The strings length is not fix.It is clear that,its only string.
thanks in advance
UILabel has a property for truncation (lineBreakMode)
http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html
If you set it to NSLineBreakByTruncatingMiddleit will truncate in the middle.
You can yet the components from your original string using [myString componentsSeparatedByString:#" - "], then you get an array. Then, create three UILabel with different font in your cell and set lineBreakMode for the second.
If you want to create this three label with cellWidth, you probably creates your cellWidth, you put your first label to the left side of the cell, the third to the right side, and you have some place left in the middle probably. This is the place of your second label. You can calculate the size of your first and third label:
CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:maxPossibleSizeOfTheLabel];
Use the lineBreakMode property of UILabel:
UILabel *label = ...
label.lineBreakMode = NSLineBreakByTruncatingMiddle;

How to vertically center detail text in a table cell of UITableViewCellStyleValue2 style?

When I do
cell.textLabel.numberOfLines = 2;
cell.detailTextLabel.numberOfLines = 1;
on a cell of UITableViewCellStyleValue2 style, the line of detail text is top-aligned, i.e. roughly at the same vertical position as the first line of (main) text is. However, I want it to be in the vertical center of the cell. Setting cell.detailTextLabel.baselineAdjustment to various values did not help. Can anyone help?
Create the custom cell with these two label and set detailtextLabel(custom) frame as your want.

How to append a UILabel to the end of text in another UILabel?

In my project, there's a UILabel in each UITableViewCell.
Text in each label varies from 1 line to 2 or 3 lines. (I get each text dynamically.)
I wonder how I can append another UILabel to the end of each text in UILabel.
I found this Q&A but the author didn't mention solution specifically.
Please let me share your ways and problem-solving. Thank you guys in advance!^^
I think I should add some information more.
For example, these are 2 labels.
This is the test Label for put in UITableView,
UITableViewCell 01/20
This is another label 01/19
Those dates(01/20, 01/19) that you can see next to each text are the another labels I wanna append. I can't append dates as a string directly cause the normal text and date are have different color and style. I tried 'sizeToFit' as some people told me, but that only show me a frame around whole text. What should I do T_T
As a variant:
UILabel *someLabel = ...
[someLabel setText:...]
[someLabel sizeToFit]
And then calculate the coordinates of the new insert UILabel.
[firstLabel sizeToFit];
CGRect frameForSecondLabel = CGRectMake(firstLabel.frame.origin.x+firstLabel.frame.size.width, firstLabel.frame.origin.y,width,height);
UILabel *secondLabel = [[UILabel alloc] initWithFrame:frameForSecondLabel];
I hope this is what you are looking for

How to calculate dynamic size on scrollview for iphone?

I have dynamic no of textviews and their size can also be dynamic, after each text view there are also dynamic no of labels, and each item is place on scroll view, so that scroll view also has dynamic size, So Someone guide me how to accomplish this task?
forgive me if this is repetitive question plz!
For setting dynamic height of UILabel or UITextView, you can implement following method
This example is for UILabel, Remember, you need to set noOfLines property before setting dynamic height, you can set noOfLines to max number.
NSString *text = #"Your text here";
CGSize size = [text sizeWithFont:lblName.font constrainedToSize:CGSizeMake(lblName.frame.size.width, 10000)];
scrollview.contentSize = CGSizeMake(scrollView.frame.size.width, size.height);
Hope this helps
What you need,
1 calculate textsize which you are going to to show on differnt controls.
for this use this line
[titleString sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(285,9999) lineBreakMode:UILineBreakModeWordWrap];
2 Also use labels instead of textView at each place if you only need to show text.
because textViews justify the text means your same line can be fit in one line but also in two lines
3 set the scrollView contentSize as above answers says.by adding all textSizes with consider some spaces between various controls.
you can set the size of scrollview using setContentSize: and query size [scrollView contentSize]

iphone programming obj-c : removing the "..."

when you enter a too long sentence for the iphone it automaticaly add a "..." at the end to show you there is other stuff you don't see right. I want to delete those "...".
image :
alt text http://img691.imageshack.us/img691/2159/screenshot20100602at095.png
Well, I'm assuming you're using a label. Look into the "lineBreakMode" property. Your solution will probably involve some combination of that property in conjunction with the "numberOfLines" property. For example, setting the "numberOfLines" property to 0 will automatically increase the height of a label to fit all text. So using that with a UILineBreakModeWordWrap would probably do the trick.
UILabel *label = [[UILabel alloc] init];
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
label.text = #"Light beer 5% 10oz Glass served cold";
[label release];
You have several options for that:
Set label's lineBreakMode property to UILineBreakModeClip - that way your sentence will just be clipped without "..." on the end
Set label's adjustsFontSizeToFitWidth property to YES - label will automatically reduce font size to fit string into available space
Make your UILabel have multiple lines - set its numberOfLines property to 0 and lineBreakMode to UILineBreakModeWordWrap. Although with this approach your label's height must be big enough to contain several lines...