1

请参阅以下附件图片。我想从 UITableViewCell. 如何从表格视图单元格中删除白色。? 在此处输入图像描述

这是我的代码:

-(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;
}
4

6 回答 6

5

UILabel背景颜色设置为clearColor,

[lbPTime setBackgroundColor:[UIColor clearColor]];
[lbPName setBackgroundColor:[UIColor clearColor]];
于 2013-03-06T09:31:11.717 回答
3

使用此代码删除白色边框。

tableView.separatorColor = [UIColor clearColor];

编辑 :

那些白块是因为UILabel你用过的。将背景颜色更改为clearColor.

lbPTime.backgroundColor = [UIColor clearColor];
lbPName.backgroundColor = [UIColor clearColor];
于 2013-03-06T09:25:52.393 回答
1

将此属性也设置为您的属性

lbPTime.backgroundColor=[UIColor clearColor];
于 2013-03-06T09:31:28.117 回答
0

要删除白色边框:

tableView.separatorColor = [UIColor clearColor];
于 2013-03-06T09:25:33.377 回答
0

我认为标签背景需要设置清晰的颜色

lbPName.backgroundColor=[UIColor clearColor];
于 2013-03-06T09:28:23.840 回答
0

嗯,这是 textLabel 的背景颜色(试试这个代码):

cell.textLabel.backgroundColor = [UIColor clearColor];

试试。

于 2013-03-06T09:28:55.413 回答