0

I am using the below code; it works but the text appears with few pixels left padding/margin.

How can I remove/adjust the cell padding/margin?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [resultaterTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.textLabel.text = [resultater objectAtIndex:indexPath.row];
}
itsazzad
  • 6,868
  • 7
  • 69
  • 89

1 Answers1

0

Use the custom cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Custom";

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

        UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:CellIdentifier] autorelease];

    }

            CGRect *customframe = CGRectMake(2, 2, 250, 30); **// Set the frame** as per your own.
            UILabel *lbl = [[UILabel alloc] initWithFrame:customframe];
            lbl.text = [resultater objectAtIndex:indexPath.row]; **// Set the label value from array**
            [cell.contentView addSubview:lbl];
            [lbl release];
return cell;

}
Ajay Sharma
  • 4,509
  • 3
  • 32
  • 59
  • 3
    This does nothing to add a margin around the cell or increase its height. – Alex Zavatone Aug 16 '13 at 15:17
  • This answer pointed out that we have to custom the content view of cell if we need padding. In this case, he add a label and specify that the margin to left and top is 2pt. – Hubert Wang Dec 17 '13 at 06:10