1

See the following attachment image.I want to remove white color from UITableViewCell. How to remove white color from tableview cell.? enter image description here

Here is my code:

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

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell=nil;

        if (cell == nil) {
         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
       }
        Schedule *sch=(Schedule*)[tableDataList objectAtIndex:indexPath.row];

        NSString*ptime=@"";

      if(sch.ptime.length<8){
        ptime=[ptime stringByAppendingString:@"  "];
        ptime=[ptime stringByAppendingString:sch.ptime];
     }
    else
   {
     ptime=[ptime stringByAppendingString:sch.ptime];
  }

    UILabel *lbPTime=[[UILabel alloc]initWithFrame:CGRectMake(5, 10, 80, 25)];
    lbPTime.font=[UIFont fontWithName:@"Zawgyi-One" size:15];
    lbPTime.textColor=[UIColor whiteColor];
   [lbPTime setText:ptime];

   NSString*pname=@"";
   pname=[pname stringByAppendingString:sch.pname];
   pname=[pname stringByAppendingString:@" "];

   UILabel *lbPName=[[UILabel alloc]initWithFrame:CGRectMake(lbPTime.frame.size.width, 10, 250, 25)];
   lbPName.font=[UIFont fontWithName:@"Zawgyi-One" size:15];

  CGSize maximumLabelSize=CGSizeMake(296, 9999);
  CGSize expectedLabelSize= [pname sizeWithFont:lbPName.font
                                            constrainedToSize:maximumLabelSize
                                                lineBreakMode:lbPName.lineBreakMode];
  CGRect newFrame=lbPName.frame;
  newFrame.size.height=expectedLabelSize.height;
  newFrame.size.width=expectedLabelSize.width;
  lbPName.frame=newFrame;
  lbPName.numberOfLines=0;
  lbPName.lineBreakMode=UILineBreakModeWordWrap;
  lbPName.textColor=[UIColor whiteColor];
  [lbPName setText:pname];

  [cell.contentView addSubview:lbPTime];
  [cell.contentView addSubview:lbPName];
  [cell.contentView sizeToFit];

  UIView *v = [[UIView alloc]init];
  v.backgroundColor = self.tableview.backgroundColor;//[UIColor clearColor];

  cell.selectedBackgroundView = v;
  cell.backgroundColor=[UIColor clearColor];
  return cell;
}
Phoenix Kyaw
  • 332
  • 1
  • 5
  • 17

6 Answers6

5

Set both UILabel Background color as clearColor,

[lbPTime setBackgroundColor:[UIColor clearColor]];
[lbPName setBackgroundColor:[UIColor clearColor]];
Vedchi
  • 1,200
  • 6
  • 14
3

Use this code to remove the white borders.

tableView.separatorColor = [UIColor clearColor];

Edit :

Those white blocks are because of the UILabel you've used. Change there background color to clearColor.

lbPTime.backgroundColor = [UIColor clearColor];
lbPName.backgroundColor = [UIColor clearColor];
Rushi
  • 4,553
  • 4
  • 33
  • 46
1

set this property also to your property

lbPTime.backgroundColor=[UIColor clearColor];
Bhanu Prakash
  • 1,493
  • 8
  • 20
0

To remove the white borders:

tableView.separatorColor = [UIColor clearColor];
ashiina
  • 996
  • 1
  • 7
  • 21
0

I think label background need to be set clear color

lbPName.backgroundColor=[UIColor clearColor];
BhushanVU
  • 3,455
  • 1
  • 24
  • 33
0

Well,it's the textLabel's background color(try this code):

cell.textLabel.backgroundColor = [UIColor clearColor];

Have a try.

junkor
  • 373
  • 1
  • 11