请参阅以下附件图片。我想从中删除白色
UITableViewCell
。如何从tableview单元格中删除白色。
这是我的代码:
-(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;
}
答案 0 :(得分:5)
将UILabel
背景颜色设为clearColor
,
[lbPTime setBackgroundColor:[UIColor clearColor]];
[lbPName setBackgroundColor:[UIColor clearColor]];
答案 1 :(得分:3)
使用此代码删除白色边框。
tableView.separatorColor = [UIColor clearColor];
编辑:
那些白色块是因为你使用的UILabel
。将背景颜色更改为clearColor
。
lbPTime.backgroundColor = [UIColor clearColor];
lbPName.backgroundColor = [UIColor clearColor];
答案 2 :(得分:1)
也将此属性设置为您的属性
lbPTime.backgroundColor=[UIColor clearColor];
答案 3 :(得分:0)
删除白色边框:
tableView.separatorColor = [UIColor clearColor];
答案 4 :(得分:0)
我认为标签背景需要设置清晰的颜色
lbPName.backgroundColor=[UIColor clearColor];
答案 5 :(得分:0)
嗯,这是textLabel的背景颜色(试试这段代码):
cell.textLabel.backgroundColor = [UIColor clearColor];
试一试。