21

我在 UITableView 中有一个 UILabel。这是我在 cellForRowAtIndexPath 中编写的代码

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(30.0, 5.0, 250.0, 35.0) reuseIdentifier:CellIdentifier] autorelease];
    }   


    CGRect rect = CGRectMake(30.0, 5.0, 250.0, 35.0);
    UILabel *label = [[UILabel alloc] initWithFrame:rect];

    label.opaque = NO;  
    label.font = [UIFont systemFontOfSize:14];
    label.numberOfLines = 2;
    label.textAlignment = UITextAlignmentCenter;            
    label.textColor = [UIColor darkGrayColor];
    label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    [label setText:@"Test Message"];    

    [cell addSubview:label];
    [label release];
    cell.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;    

我的意图是将单元格和 UILabel 的背景设置为透明。

但它不起作用。谁能告诉我我在这里缺少什么

谢谢

桑迪普

4

3 回答 3

74

更改以下行:

label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];

对此:

label.backgroundColor = [UIColor clearColor];
于 2010-02-24T12:12:23.433 回答
2

对于那些使用 Xamarin.iOS 的人来说,这显然是:

UILabel myLabel = new UILabel();
myLabel.Text = "Hello world!";
myLabel.BackgroundColor = UIColor.Clear;
于 2013-04-20T12:38:03.933 回答
1
[label setBackGroundColor:[UIColor clearColor]];

为标签设置 clearBackGround 颜色

于 2014-03-03T15:10:46.327 回答