开发者

setting transparent background for UILabel for iphone application

开发者 https://www.devze.com 2022-12-20 12:11 出处:网络
I have a UILabel in UITableView. Here is the code i have written in cellForRowAtIndexPath UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

I have a UILabel in UITableView. Here is the code i have written in 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;    

My intention was to set the background of 开发者_开发知识库cell and UILabel as transparent.

But it is not working. can any one tell me what i am missing here

Thanks

Sandeep


Change the following line:

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

to this:

label.backgroundColor = [UIColor clearColor];


For those using Xamarin.iOS it's obviously:

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


[label setBackGroundColor:[UIColor clearColor]];

To set the clearBackGround Color for a label

0

精彩评论

暂无评论...
验证码 换一张
取 消