小编use*_*520的帖子

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

我在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;    
Run Code Online (Sandbox Code Playgroud)

我的目的是将单元格和UILabel的背景设置为透明.

但它没有用.任何人都可以告诉我这里缺少什么

谢谢

桑迪普

transparent uilabel

21
推荐指数
1
解决办法
3万
查看次数

标签 统计

transparent ×1

uilabel ×1