UITableView cell multiline justification - iphone

I have seen questions posted on here asking how to left and right align two lumps of text, but how can I neatly left and right justify an entire paragraph inside a multiline cell? (Such as what MS Word etc would do if you click on the justification button so that left and right sides of the text are always aligned).

You can also create a custom cell with label which IBOutlet to this class that can be downloaded on github OHAttributedLabel, then try the code below
cell.label.textAlignment = UITextAlignmentJustify;

Is this what you're looking for?
yourTextLabel.textAlignment = UITextAlignmentCenter;
Along with the frame size that you want for your text label.

Related

Add margin between table and text underneath, MS Office Word 2007

I am having a difficult time adding space between a table and paragraphs underneath.
I am trying to create a table style that has some bottom margin or spacing but it doesn't seem to work... note that I am not referring to cell spacing.
For individual tables, I had some success by changing Table Properties-->Text wrapping to around, and setting the positioning to top 3pt, bottom 3pt, and some large number for left and right.
Though text wrapping is greyed out when I am creating a table style.
Any ideas?
Tim
Will it be ok for you if the paragraph style is having a top margin/spacing?
If yes, please try duplicating a style and modify it , From the Format> select the option "paragraph" and add top spacing as desired.Shall give the step if unable to find.

How to format different characters in a UILabel's string differently?

I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
Use a UIWebView and render the text as HTML.
I ended up using the textRectForBounds:limitedToNumberOfLines: to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.

UITextView scroll only horizontally

I have one line of text that is too long to be displayed in one single line in a UILabel, so I switched to a UITextView. I wanted to display that text still in one line, and be able to scroll horizontally, but instead, the UITextView will wrap the text into multiple lines, and allow me to scroll vertically. So, for the text "This is a very very long line", instead of displaying it like "This is a ", and then if scrolled horizontally, it would display the rest of it, it actually displays it like "This is a \n very very long \n line". How can I get the behavior I want?
Thanks,
Mihai
If you want that behavior you should place the label inside a scrollview. That's the only way you'll be able to scroll a label in any direction.
Using Merrimack's advice, this worked for me:
self.dishNameLabel.text = #"Here is some very longgggg text to test with";
float width = ceil([self.dishNameLabel.text sizeWithAttributes:#{NSFontAttributeName: [UIFont fontWithName:#"WorkSans-SemiBold" size:15.0]}].width);
self.dishNameLabel.frame = CGRectMake(self.dishNameLabel.frame.origin.x, self.dishNameLabel.frame.origin.y, width, self.dishNameLabel.frame.size.height);
self.dishNameScrollView.contentSize = CGSizeMake( width, self.dishNameScrollView.frame.size.height);
Of course, you will have to replace your text and font with your respective specs

how to use paragraph text in uitableviewcell in cocoa-touch

I've been using uiLabels to put text in the cells of tableviews. I want to now use paragraph text that carriage returns to the next line instead of going out of the boundaries of the table cell. Would I do this by manipulating a uiLabel or would I use a different control all together like a text view.
Also is there any project examples out there that implement this?
Thanks,
Joe
Simplest way is to use a UILabel and set the number of lines in IB to > 1 then set the line break to "Word Wrap."
Another way is to use a UITextView, load the data and set it to 'disabled' so it can't be edited.
Finally, you can always go the UIWebView route and load it with formatted HTML, complete with line breaks, etc. Pretty heavy, but most flexible.
The simplest approach is to use a UILabel, probably. The only alternative would be to make a custom UIView subclass that draws the text directly, but that will give you marginal benefit.

Problem in displaying texts in each cell of the UITableView control on iPhone

I display texts in a cell of the UITableView control. Now the texts that I display can be large enough to fit inside one cell width, so it displays the texts on the second line. But it breaks the word in the middle, (like if say "That sounds great, I will pick you up from the abc station", it will display "That sounds great, I will pick you up from the abc sta" on the first line and "tion" on the second line. However, I wanted to be like "That sounds great, I will pick you up from the abc" on the first line and "station" on the second line).
Could you let me know how can I do that?
Thanks.
I think you can achieve this by setting the lineBreakMode on the UILabel.
// setup cell 3.0 SDK code
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.text = #"this is some really long string....";