Custom table cells

Discussion in 'iOS Programming' started by r00li, Sep 19, 2009.

  1. r00li macrumors member

    Joined:
    Sep 27, 2008
    #1
    I have created a custom table cell in interface builder that I am using. I have two problems with it.

    The first one - I am using grouped table View and the corners of the cell are not rounded.

    Second in that table cell I have a label on the bottom. I want to resize the whole cell and the label if there is too much text to fit. Text is loaded from an NSArray. But I don't know how the resize the cell and the label so that the text can fit.

    This is how the cell looks like:
    ----------------------
    |.........| some text
    |image|
    |.........| other text

    resizable text
    -----------------------
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    To resize the cell, look into the UITableViewDelegate method tableView:heightForRowAtIndexPath:.
     
  3. r00li thread starter macrumors member

    Joined:
    Sep 27, 2008
    #3
    I know how resize the cell. Problem is with resizing the label and then resizing the cell. I must resize the label to fit the text before I can resize the cell.
     
  4. r00li thread starter macrumors member

    Joined:
    Sep 27, 2008
    #4
    Yust found a simple method on the internet and simplified it a lot.

    Code:
    		CGFloat size = 15; //Font size
    		
    		//Calculate the expected size based on the font and linebreak mode of the label
    		CGFloat maxWidth = [UIScreen mainScreen].bounds.size.width - 50;
    		CGFloat maxHeight = 9999;
    		CGSize maximumLabelSize = CGSizeMake(maxWidth,maxHeight);
    		CGSize expectedLabelSize = [[detajli objectAtIndex:3] sizeWithFont:[UIFont systemFontOfSize:size] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; 
    			
    		return expectedLabelSize.height + 150;
    //[detajli objectAtIndex:3] is a NSString
    Now the remaining problem are the section corners. For some reason they are not rounded. They are flat and it looks bad.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    If you inset the views that are at the left and right edges of the cell several pixels you should see the rounded corners. If that doesn't work show a screenshot.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Sorry, I wasn't able to detect that based on your first post.
     
  7. r00li thread starter macrumors member

    Joined:
    Sep 27, 2008
    #7
    Great that worked!

    I should probably improve my writing style!:rolleyes:
     

Share This Page