iPhone自定义单元格 - 透明标签背景

时间:2009-06-10 12:43:04

标签: iphone label

图片胜过千言万语:)

alt text

这是代码:


// Initialization code
        UIView *myContentView = self.contentView;
        UIImage *image = [UIImage imageNamed: @"bg_top.png"];
        UIImageView *imageview = [[UIImageView alloc] initWithImage: image];
        self.backgroundView = imageview;
        [imageview release];
        self.label = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor redColor] fontSize:15.0 bold:YES]; 
        self.label.textAlignment = UITextAlignmentLeft; 
        [myContentView addSubview:self.label];
        [self.label release];

    self.textField = [[UITextField alloc] init];
    [self.textField setTextColor:[UIColor grayColor]];
    self.textField.font = [UIFont systemFontOfSize:13.0];
    //self.textField.secureTextEntry = YES;
    [self.textField setKeyboardType:UIKeyboardTypeEmailAddress];
    myContentView.backgroundColor = [UIColor clearColor];
    [myContentView addSubview:self.textField];
    [self.textField release];

问题是如何从标签中删除丑陋的白色背景并使其透明。

3 个答案:

答案 0 :(得分:6)

或者:

self.label.backgroundColor = [UIColor clearColor];

答案 1 :(得分:0)

尝试使用以下方式设置背景颜色:

[self.label setBackgroundColor: [UIColor colorWithWhite: 1.0f alpha: 0.0f]];

或将Alpha值设置为0

[self.label setAlpha: 0.0f];

希望这样做。

答案 2 :(得分:0)

总结一下。根据您的所有回复,最佳解决方案是:

[self.label setBackgroundColor:[UIColor clearColor]];