1

I have a UiTableView and it displays the text on the view it goes to, however I don't want it to show the three dots aftera certain amount of words. How can I do this?

EDIT

Thank you all for the help, I figured it out.

Through storyboard, I just changed the Line Break mode from Truncating Tail to Word Wrap, I think Clip might word as well.

rmaddy
  • 298,130
  • 40
  • 468
  • 517
  • http://stackoverflow.com/questions/9827126/change-the-uitableviewcell-height-according-to-amount-of-text u can check this ...this create label in tableview cell based text – Anjaneyulu Jul 12 '13 at 06:32

4 Answers4

1

IF text is long and truncated then use lineBreakMode NSLineBreakByWordWrapping instead of NSLineBreakByTruncatingTail

i.e cell.textTitle.lineBreakMode = NSLineBreakByWordWrapping
Rigel Networks
  • 4,766
  • 2
  • 22
  • 41
  • Thank you Divya, you gave me the right idea, I changed the line break mode to "word wrap" from "truncated tail" through storyboard. – Spencer Lively Jul 12 '13 at 06:58
1

Please try below code :

    #define FONT_SIZE 14.0f
    #define CELL_CONTENT_WIDTH 300.0f
    #define CELL_CONTENT_MARGIN 3.0f



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    NSString *text = [ObjectsArr objectAtIndex:indexPath.row];
    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    CGFloat height = MAX(size.height, 44.0f);
    return height + (CELL_CONTENT_MARGIN * 2);
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [ObjectsArr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UILabel *label = nil;
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        label = [[UILabel alloc] initWithFrame:CGRectZero];

            [label setLineBreakMode:UILineBreakModeWordWrap];
            [label setMinimumFontSize:FONT_SIZE];
            [label setNumberOfLines:0];
            [label setFont:[UIFont systemFontOfSize:FONT_SIZE]];
            [label setTag:1];
            [[cell contentView] addSubview:label];
    }

        NSString *text = [ObjectsArr objectAtIndex:indexPath.section];

        CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
        CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
        if (!label)
            label = (UILabel*)[cell viewWithTag:1];

        [label setText:text];
        [label setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];


    return cell;
}

Let me know if you find any difficulties. Thanks.

sagarcool89
  • 1,366
  • 8
  • 16
0

That means the text is too long and gets truncated. You can adjust the row height to display the text fully or you may use a shorter text instead.

quaertym
  • 3,737
  • 2
  • 26
  • 38
0

One option is to find the max length based on the size of the cell and then only show the left n digits. This will ensure that you never see the ...

[@"abc xyz http://www.abc.com aaa bbb ccc" substringWithRange:NSMakeRange(8, 18)]

Code from: Objective-C: Best way to extract substring from NSString?

Community
  • 1
  • 1
logixologist
  • 3,856
  • 3
  • 23
  • 43