Search code examples
cocoa-touchipaduitableviewtextlabel

re size the UITable view textlabel


I created a UITableView and wrote the following code in cellForRowAtIndexPath

static NSString *CellIdentifier = @"RootViewControllerCellIdentifier";

UITableViewCell *cell = [self.tableView queueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    cell.selectionStyle = UITableViewCellSelectionStyleGray;    

}

// Set appropriate labels for the cells.
switch (indexPath.row) {
    case 0:
        cell.textLabel.text = @"Static Scenes";             
        **[cell.textLabel setFrame:CGRectMake(200, 20, 500,600)];**
        cell.imageView.image=[UIImage imageNamed:@"RunOptionsImage.png"];
        cell.imageView.frame=CGRectMake(15, 20, 55, 65);
        break;

as you can understand from the above code, i have a tableview cell textLabel named as Static Scenes .

in this code [cell.textLabel setFrame:CGRectMake(200, 20, 500,600)]; i am planning to set the frame of textLabel.but it not resizing according to the frame i set. i used this cell.textLabel.frame = CGRectMake(200, 20, 500,600) code also. can any one tell me a good way to re size the text label.


Solution

  • In addition to altering the text label's size you will also need to return an appropriate height in the tableView:heightForRowAtIndexPath: method. Otherwise, any layout changes won't reflect.