0

I would like to set the frame width of my UITableViewCell label inside tableView:cellForRowAtIndexPath: how ever I am receiving an error.

this is how I am trying to set the cell up.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

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

        [cell.textLabel setLineBreakMode:UILineBreakModeCharacterWrap];
        cell.textLabel.frame.size.width = 200.0; // just as an example.
        [cell.textLabel setMinimumFontSize:FONT_SIZE];
        [cell.textLabel setNumberOfLines:0];
        [cell.textLabel setFont:[UIFont boldSystemFontOfSize:FONT_SIZE]];
        [cell.textLabel setTag:1];

        [[cell contentView] addSubview:cell.textLabel];
    }

but on the line where I try to set textLabel.frame.size.width I get this error

Expression is not assignable

HurkNburkS
  • 5,492
  • 19
  • 100
  • 183

2 Answers2

1

It is self explainable as you can not change width and height property for the UITableViewcell.And more importantly, you can not change the frame of textLabel in UITableViewCell. You should customize the UITableViewCell class.

Krunal
  • 6,440
  • 21
  • 91
  • 155
BornCoder
  • 1,046
  • 8
  • 10
1

You cannot do this, if you want to do this then it will not give any error but it will not affect on you code.....So just make simple label and then set frame of it then add it to your cell.

[cell addSubview:YourLbl];
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74