2009-06-10 8 views
1

絵はここでは、コードである以上千の言葉:)iPhoneカスタムセル - 透明ラベルの背景

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]; 

どのように質問ですが、その醜い白い背景をラベルから取り除いて透明にします。

+0

私たちはnewLabelWithPrimaryColorを参照する必要があります。また、メモリ管理が間違っているようです。 – Eiko

答えて

0

はと背景色を設定してください:0

[self.label setAlpha: 0.0f]; 

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

またはアルファ値を設定し、トリックを行います希望。

+2

これを行うためのUIColorインスタンスが既に存在します:[self.label setBackgroundColor:[UIColor clearColor]]; –

+0

上記の明瞭な色のほかに、アルファを設定すると完全なラベルが消えてしまいます。 – Eiko

6

または代わり:

self.label.backgroundColor = [UIColor clearColor]; 
0

だけで物事を総括します。すべての回答に基づいて、最良の解決策は次のとおりです。

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