为UILabel为iphone应用程序设置透明背景

时间:2010-02-16 07:05:33

标签: uilabel transparent

我在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的背景设置为透明。

但它不起作用。任何人都可以告诉我这里缺少什么

由于

和Sandeep

3 个答案:

答案 0 :(得分:74)

更改以下行:

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

到此:

label.backgroundColor = [UIColor clearColor];

答案 1 :(得分:2)

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

UILabel myLabel = new UILabel();
myLabel.Text = "Hello world!";
myLabel.BackgroundColor = UIColor.Clear;

答案 2 :(得分:1)

[label setBackGroundColor:[UIColor clearColor]];

为标签设置clearBackGround颜色

相关问题